Spring Boot的JMS发送和接收队列消息,基于ActiveMQ

return “SimpleMsg{” +

“to='” + to + ‘’’ +

“, body='” + body + ‘’’ +

‘}’;

}

}

SimpleMsg将作为spring boot程序中消息的实体传输。

定义一个spring boot的消息接收器:

import org.springframework.jms.annotation.JmsListener;

import org.springframework.stereotype.Component;

@Component

public class MsgReceiver {

//destination的值和在application里面发送制定的目的地值需要相同才能收到

//containerFactory的变量名对应在app里面定义的JmsListenerContainerFactory

@JmsListener(destination = “@zhangphil”, containerFactory = “myAppContainerFactory”)

public void receiveMessage(SimpleMsg msg) {

System.out.println(“收到消息->”);

System.out.println(msg);

System.out.println(“收到消息<-”);

}

}

完成spring boot的应用application:

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;

import org.springframework.context.ConfigurableApplicationContext;

import org.springframework.context.annotation.Bean;

import org.springframework.jms.annotation.EnableJms;

import org.springframework.jms.config.DefaultJmsListenerContainerFactory;

import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;

import org.springframework.jms.core.JmsTemplate;

import org.springframework.jms.support.converter.MappingJackson2MessageConverter;

import org.springframework.jms.support.converter.MessageConverter;

import org.springframework.jms.support.converter.MessageType;

@SpringBootApplication

@EnableJms

public class SpringJmsApplication {

@Bean

public JmsListenerContainerFactory<?> myAppContainerFactory(ConnectionFactory connectionFactory,

DefaultJmsListenerContainerFactoryConfigurer configurer) {

DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

configurer.configure(factory, connectionFactory);

return factory;

}

@Bean

public MessageConverter jmsMessageConverter() {

MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();

converter.setTargetType(MessageType.TEXT);

converter.setTypeIdPropertyName(“_type”);

return converter;

}

public static void main(String[] args) {

ConfigurableApplicationContext context = SpringApplication.run(SpringJmsApplication.class, args);

JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);

SimpleMsg msg = new SimpleMsg(“zhangfly”, “Hello,world!”);

System.out.println(“发送消息:” + msg);

jmsTemplate.convertAndSend(“@zhangphil”, msg);

System.out.println(“发送结束”);

}
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)

img

总结

阿里伤透我心,疯狂复习刷题,终于喜提offer 哈哈~好啦,不闲扯了

image

1、JAVA面试核心知识整理(PDF):包含JVMJAVA集合JAVA多线程并发,JAVA基础,Spring原理微服务,Netty与RPC,网络,日志,ZookeeperKafkaRabbitMQ,Hbase,MongoDB,Cassandra,设计模式负载均衡数据库一致性哈希JAVA算法数据结构,加密算法,分布式缓存,Hadoop,Spark,Storm,YARN,机器学习,云计算共30个章节。

image

2、Redis学习笔记及学习思维脑图

image

3、数据面试必备20题+数据库性能优化的21个最佳实践

image
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门即可获取!
FLJ-1712193843677)]

3、数据面试必备20题+数据库性能优化的21个最佳实践

[外链图片转存中…(img-piqM1tON-1712193843677)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》点击传送门即可获取!

  • 9
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值