JMS(Jboss Messaging)的一点使用心得(二)使用Spring

SpringJMS支持得非常好,使用起来也很方便;下面是使用Spring的方法。

准备工作:

想要运行Messaging客户端,需要几个包,请参见< http://labs.jboss.com/file-access/default/members/jbossmessaging/freezone/docs/userguide-1.4.0.SP1/html/installation.html>

1.配置JMS ConnectionFactory

    <jee:jndi-lookup id="jmsConnectionFactory" jndi-name="ConnectionFactory">
        
<jee:environment>
            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            java.naming.provider.url=localhost:1099
        
</jee:environment>
    
</jee:jndi-lookup>


2
.配置发送JMSJmsTemplate

    <bean id="jmsTemplate" lazy-init="true" class="org.springframework.jms.core.JmsTemplate">
        
<property name="connectionFactory" ref="jmsConnectionFactory" />
        
<property name="defaultDestinationName" value="A" />
 
</bean>


3.配置JMS的接收器

<bean id="messageListener" class="jms.receiver.SimpleMessageListener" />


Class必须实现javax.jms.MessageListener接口

4.配置JMS ListenerContainer

    <bean id="listenerContainerQueue" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        
<property name="concurrentConsumers" value="1" />
        
<property name="connectionFactory" ref="jmsConnectionFactory" />
        
<property name="destinationName" value="A" />
        
<property name="messageListener" ref="messageListener" />
        
<property name="exceptionListener" ref="exceptionListener" />
    
</bean>


5.如果需要的话,配置JMS ExceptionListener

<bean id="exceptionListener" class="jms.receiver.SimpleExceptionListener" />

同理,该Class必须实现javax.jms.ExceptionListener接口

6
.发送Jms消息

        String strTest = "JmsTest";
        BeanFactory factory = 
new ClassPathXmlApplicationContext("applicationContext_Sender.xml");
        JmsTemplate template = (JmsTemplate) factory.getBean("jmsTemplate");
        template.convertAndSend(strTest);
        System.out.println(strTest);


7
.接收Jms消息

BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext_Receiver.xml");

只需要初始化配置文件就可以接收了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot Messaging: Messaging APIs for Enterprise and Integration Solutions by Felipe Gutierrez English | 5 Jun. 2017 | ISBN: 1484212258 | 196 Pages | PDF | 6.36 MB Build messaging applications using the power of Spring Boot; use Spring application events over the Web; use WebSocket, SockJS, and STOMP messaging with Spring MVC; and use Spring JMS, Redis Pub/Sub and Spring AMQP for reliable messaging solutions. This book covers all the Spring Messaging APIs using Spring Boot. Written by a Pivotal engineer, Spring Boot Messaging is an authoritative guide to the many messaging APIs and how to use these for creating enterprise and integration solutions. You will learn and integrate these messaging APIs with more complex enterprise and cloud applications: for example, you will see how to use Spring Cloud Stream for creating message-driven and cloud native microservices. In addition, you’ll discover the new Spring Integration DSL and use it with Spring Cloud Stream to build integration solutions using every enterprise integration pattern. Finally, you’ll see Spring Reactor and Spring Cloud to take your application to the next level. After reading this book, you will come away with a case study application walk-through and will be able to use it as a template for building your own Spring messaging applications or messaging features within your enterprise or cloud application. What You'll Learn Use the main Spring messaging APIs with Spring Framework 5 Build messaging applications over the Web Use WebSocket, SockJS, and STOMP messaging Integrate Spring JMS and Spring AMQP into your applications Work with Spring Cloud Stream and microservices Who This Book Is For Enterprise Java developers who have at least some previous experience with the Spring Framework and/or the Spring platform.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值