消息格式定义:
StreamMessage:数据流
MapMessage:名称-值对
TextMessage:字符串对象
ObjectMessage:序列化的Java对象
BytesMessage:字节数据流
Spring整合JMS在src/main/resources下创建spring配置文件applicationContext-jms-producer.xml在sping.xml配置文件中配置 jsmTemplate 队列模式 应是ActiveMQQueue 发布订阅模式 ActiveMQTopic运营商后台执行商品审核后向ActiveMQ发送消息 搜索服务从ActiveMQ收到消息并导入到索引库
在运营商controller层
@Autowired private Destination destination 点对点模式 @Autowired private JmsTemplate jmsTemplate 将商品list集合转化成json字符串 String jsonString=JSON.toJSONString(itemList)jmsTemplate.send(destination ,new messageCreater(){ return session.createTextMessage (jsonString) })消费者在搜索服务项目中的xml文件中应配置 监听类的引用
在项目的serviceImpl中 写java类实现 MessageListener重写 onMessage接口String text =message.getText() 获取数据JSON.parseArray(text,tbItem.class)网页静态使用ActiveMQ 发布订阅模式 生产者发送 商品id消费者接受id 根据id查询商品信息生成静态化网页
