In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to analyze the ActiveMQ message queuing technology integration Spring process, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
I. Business logic
I want to send a broadcast to the corresponding listener when modifying the status of an item. The item is stored in solr and a detailed page of the current item is generated through the static template of the web page. In this case, the broadcast mechanism is used.
When I delete an item, I send a broadcast to the corresponding listener and delete the corresponding item in the solr.
Broadcast mechanism: you must be online at the same time in order to receive my message
Configuration files need to be imported to use message middleware
Publish a broadcast:
If ("1" .equals (status)) {jmsTemplate.send (topicPageAndSolrDestination, new MessageCreator () {@ Override public Message createMessage (Session session) throws JMSException {TextMessage textMessage = session.createTextMessage (String.valueOf (id)); return textMessage;}});}
Listener 1, store the current merchandise in solr: server configuration file that operates solr
# corresponding to listen for messages that are executed to save inventory in solr
Listener class
Public class ItemSearchListener implements MessageListener {@ Autowired private SearchService searchService; @ Autowired private ItemDao itemDao; @ Override public void onMessage (Message message) {/ / get the broadcast issued by the producer and add the inventory list ActiveMQTextMessage atm = (ActiveMQTextMessage) message; try {/ / to the solr to get the data in the broadcast. Long goodsId = Long.valueOf (atm.getText ()); / / query the inventory table ItemQuery query = new ItemQuery (); ItemQuery.Criteria criteria = query.createCriteria (); criteria.andGoodsIdEqualTo (goodsId) through the passed commodity id; / / query the inventory table List items = itemDao.selectByExample (query) of the corresponding commodity id; / / call the corresponding method to add the current inventory information searchService.importList (items) to solr } catch (JMSException e) {e.printStackTrace ();}
Listener class 2: configuration file
Listener class 2: generate static web page templates
Public class PageListener implements MessageListener {@ Autowired private CmsService cmsService; @ Override public void onMessage (Message message) {ActiveMQTextMessage atm = (ActiveMQTextMessage) message; try {Long goodsId = Long.valueOf (atm.getText ()); Map goodsData = cmsService.findGoodsData (goodsId); cmsService.createStaticPage (goodsId,goodsData);} catch (Exception e) {e.printStackTrace ();}
Point to point
When I delete an item, I need the corresponding service to delete the inventory information in solr, adding and deleting using the same service and using the configuration file above
/ / publish a broadcast. @ Autowired private ActiveMQTopic topicPageAndSolrDestination;// broadcasts the idif (ids.length > 0) of the current product in the modified code method {jmsTemplate.send (queueSolrDeleteDestination, new MessageCreator () {@ Override public Message createMessage (Session session) throws JMSException {TextMessage textMessage = session.createTextMessage (String.valueOf (ids)); return textMessage;}});}
# delete inventory information public class ItemDeleteListener implements MessageListener {@ Autowired private SearchService searchService; @ Override public void onMessage (Message message) {ActiveMQTextMessage atm = (ActiveMQTextMessage) message; try {Long goodsId = Long.valueOf (atm.getText ()); searchService.deleteById (goodsId);} catch (JMSException e) {e.printStackTrace ();}
On how to parse ActiveMQ message queuing technology integration Spring process to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un