<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> </dependency>
在调试过程中红色参数一定要设置为false。测试成true会报错。一直没有找到原因,TBD。
spring.activemq.broker-url=tcp://xxx.xxx.xxx.xxx:61616 spring.activemq.user=admin spring.activemq.password=admin spring.activemq.pool.enabled=false spring.activemq.pool.max-connections=100
启动类添加@EnableJms注解。JmsListenerContainerFactory用于支持既能订阅有能点对点。最后一段代码中用到
@EnableJms
……
@Bean public JmsListenerContainerFactory<?> jmsListenerContainerFactoryTopic(ConnectionFactory activeMQConnectionFacotry) { DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory(); bean.setPubSubDomain(true); bean.setConnectionFactory(activeMQConnectionFacotry); return bean; }
public interface ProducterService { public void sendMessage(Destination destination, final String message); public void sendMessage(final String message); public void publish(final String msg); }
@Service public class ProducterServiceImpl implements ProducterService { @Autowired private Queue queue; @Autowired private JmsMessagingTemplate jmsTemplate; @Override public void sendMessage(final String message) { jmsTemplate.convertAndSend(this.queue,message); } @Override public void sendMessage(Destination destination, final String message) { jmsTemplate.convertAndSend(destination,message); } @Autowired private Topic topic; @Override public void publish(String msg) { jmsTemplate.convertAndSend(this.topic,msg); } }
@RestController @RequestMapping("/order") public class OrderMQController { @Autowired private ProducterService producter; @RequestMapping("/done") public Object order (String msg) { producter.sendMessage(msg); return "success"; } @RequestMapping("/done1") public Object order1 (String msg) { Destination destination = new ActiveMQQueue("order.queue"); producter.sendMessage(destination,msg); return "success"; } @RequestMapping("/publish") public Object publishOrder(String msg) { producter.publish(msg); return "success"; } }
@Component public class OrderConsumer { @JmsListener(destination = "order.queue") public void receiveQueue(String text) { System.out.println("OrderConsumers收到:"+text); } }
@Component public class TopicConsumer { // @JmsListener如果不指定独立的containerFactory的话只能支持一直模式:或者是点对点,或者是消息订阅 @JmsListener(destination = "kevin.topic", containerFactory="jmsListenerContainerFactoryTopic") public void receiveTopic1(String text) { System.out.println("TopicConsumers1收到:"+text); } @JmsListener(destination = "kevin.topic", containerFactory="jmsListenerContainerFactoryTopic") public void receiveTopic2(String text) { System.out.println("TopicConsumers2收到:"+text); } @JmsListener(destination = "kevin.topic") public void receiveTopic3(String text) { System.out.println("TopicConsumers3收到:"+text); } }
@Component public class TopicConsumer { // @JmsListener如果不指定独立的containerFactory的话只能支持一直模式:或者是点对点,或者是消息订阅 @JmsListener(destination = "kevin.topic", containerFactory="jmsListenerContainerFactoryTopic") public void receiveTopic1(String text) { System.out.println("TopicConsumers1收到:"+text); } @JmsListener(destination = "kevin.topic", containerFactory="jmsListenerContainerFactoryTopic") public void receiveTopic2(String text) { System.out.println("TopicConsumers2收到:"+text); } @JmsListener(destination = "kevin.topic") public void receiveTopic3(String text) { System.out.println("TopicConsumers3收到:"+text); } }
相关推荐
springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot...
该资源为springBoot集成消息队列ActiveMQ的实现demo,包括通过java代码连接ActiveMQ,实现简单的生产者、消费者通信
SpringBoot整合框架各种实用的组件技术点以及一些框架重要技术点的项目案例的实现,纯属个人技术积累和框架学习,有缺漏之处请指出。 主体版本号 java v1.8 springboot v2.0.5.RELEASE 各技术点预览目录 组件名称...
apache-activemq-5.16.0.zip
springboot + activemq 整合 ,其中springboot-activemq-consumer 是消费端,springboot-activemq-producer 生成者 ,启动生成者,会默认生成100个消息,启动消费端,会消费生产的100个消息
apache-activemq-5.9.0-bin.zip
springboot-learning-1 springboot框架相关技术的案例项目及使用springboot框架时的需注意点 项目介绍 SpringBoot集成框架各种实用的组件技术点以及一些框架重要技术点的项目案例的实现,纯属个人... SpringBoot整合E
Springboot和ActiveMQ的整合实例
springboot集成activemq实现消息接收demo
ActiveMQ是Apache下的开源项目,完全支持JMS1.1和J2EE1.4规范的JMS Provider实现。 由于ActiveMQ是一个纯Java程序,因此只需要操作系统支持Java虚拟机,ActiveMQ便可执行。 activemq的queue和topic JMS中定义...
添加基于消息的最终一致性分布式事务解决方法+springboot整合rocketmq 四期: 缓存和mysql数据一致性问题的解决方案+redis分布式锁解决缓存雪崩和缓存击穿的问题 # 部署: 先启动提供者,再启动web消费者 java -...
apache-activemq-5.8.0-bin.zip
apache-activemq-5.15.15二进制包,安装包,apache-activemq-5.15.15-bin.tar.gz
springboot整合 activeMq 消费者 消费接收消息 包含队列模式点对点发 以及 主题模式一对多 这是消费者的demo consumer 。 里面有消息重发机制,手动确认ACK模式。 配合 producer 生产者demo使用。
解压缩apache-activemq-5.5.1-bin.zip,然后双击apache-activemq-5.5.1\bin\activemq.bat运行ActiveMQ程序。 包含了apache-activemq-5.5.1-bin.zip以及ActiveMQ一个helloworld的demo启动ActiveMQ以后,登陆:...
spring boot 实践学习案例,与其它组件结合如 mybatis、jpa、dubbo、redis、mongodb、memcached、kafka、rabbitmq、activemq、elasticsearch、security、shiro等 #### Spring Boot 版本 - 2.0.3.RELEASE #### 模块...
apache-activemq-5.15.3-bin apache-activemq-5.15.3-bin
activemq-pool-5.8.0-sources.jar