<!--这个是队列目的地,点对点-->
<bean id="queueSolrDeleteDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="pinyougou_queue_solr_delete"/>
</bean>
@Autowired
private Destination queueSolrDeleteDestination;//用户在索引库中删除记录
/**
*批量删除
*@param ids
*@return
*/ @RequestMapping("/delete")
public Result delete(final Long [] ids){
try {
goodsService.delete(ids); jmsTemplate.send(queueSolrDeleteDestination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createObjectMessage(ids);
}
});
return new Result(true, "删除成功");
} catch (Exception e) { e.printStackTrace();
return new Result(false, "删除失败");
}
}
<!--这个是队列目的地,点对点的 文本信息 (删除索引库中记录) -->
<bean id="queueSolrDeleteDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="pinyougou_queue_solr_delete"/>
</bean>
<!-- 消息监听容器(删除索引库中记录) -->
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="queueSolrDeleteDestination" />
<property name="messageListener" ref="itemDeleteListener" />
</bean>
/**
*监听:用于删除索引库中记录
*@author Administrator
*
*/ @Component
public class ItemDeleteListener implements MessageListener{
@Autowired
private ItemSearchService itemSearchService;
@Override
public void onMessage(Message message) {
try {
ObjectMessage objectMessage= (ObjectMessage)message; Long[] goodsIds = (Long[]) objectMessage.getObject();
System.out.println("ItemDeleteListener 监听接收到消息..."+goodsIds);
itemSearchService.deleteByGoodsIds(Arrays.asList(goodsIds)); System.out.println("成功删除索引库中的记录");
} catch (Exception e) { e.printStackTrace();
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |