Spring JMS Integration Gateway Example 12 minute read
A detailed step-by-step tutorial on how to connect to a JMS broker using a Spring Integration Gateway and Spring Boot.
In our first lesson, you will get introduced to the concepts of Enterprise Application Integration. You will learn about the and Enterprise integration patterns that can be applied to simplify integration between different platforms and the Integration strategies that can be followed for this purpose. Finally, we will discuss how and why to implement a Message driven architecture and how to achieve both Synchronous and asynchronous communication among nodes.
In this lesson, you will get to understand how Spring Integration works under the hood. The core concepts of Spring Integration messaging system (like message channels and endpoints) will be introduced. Additionally, the components that build the framework will be discussed, including the channel adapters, transformers, filters, routers etc. Finally, the two distinct methods of communication (synchronous and asynchronous) are explained and the lesson ends with a discussion on error handling.
In this lesson, we will focus on the integration with external web services. Spring Integration comes with the necessary functionality (adapters, channels etc.) to support web services out of the box. A full example is built from scratch in order to better understand the topic.
In this lesson, we will focus on integrating our application with JMS messaging. For this purpose, we will use Active MQ, which will be our broker. We will show examples of sending and receiving JMS messages by using the Spring Integration JMS channel adapters. Following these examples, we will see some ways of customizing these invocations by configuring message conversion and destination resolution.
In this lesson, we will wrap everything up by providing a complete application that uses several of the components provided by Spring Integration in order to provide a service to its users. We will discuss the system architecture, the actual implementation and the relevant error handling.
In this lesson, we will examine different mechanisms of monitoring or gathering more information about what is going on within the messaging system. Some of these mechanisms consist of managing or monitoring the application through MBeans, which are part of the JMX specification. Another mechanism discussed in this chapter is how we will implement the EIP idempotent receiver pattern using a metadata store. Finally, the last mechanism described is the control bus. This will let us send messages that will invoke operations on components in the application context.
Enterprise integration is too complex to be solved with a simple 'cookbook' approach. Instead, patterns can provide guidance by documenting the kind of experience that usually lives only in architects' heads: they are accepted solutions to recurring problems within a given context. Patterns are abstract enough to apply to most integration technologies, but specific enough to provide hands-on guidance to designers and architects. Patterns also provide a vocabulary for developers to efficiently describe their solution.
Patterns are not 'invented'; they are harvested from repeated use in practice. If you have built integration solutions, it is likely that you have used some of these patterns, maybe in slight variations and maybe calling them by a different name. The purpose of this site is not to "invent" new approaches, but to present a coherent collection of relevant and proven patterns, which in total form an integration pattern language.
Despite the 700+ pages, our book covers only a fraction of patterns (and the problems to be solved) in the integration space. The current patterns focus on Messaging, which forms the basis of most other integration patterns. We have started to harvest more patterns but are realizing (once again) how much work documenting these patterns really is. So please stay tuned.
We have documented 65 messaging patterns, organized as follows:
A detailed step-by-step tutorial on how to connect to a JMS broker using a Spring Integration Gateway and Spring Boot.
A detailed step-by-step tutorial on how to connect to Apache ActiveMQ Artemis using Spring JMS and Spring Boot.
A detailed step-by-step tutorial on how to publish/subscribe to a JMS topic using Spring JMS and Spring Boot.
A detailed step-by-step tutorial on how to connect to an ActiveMQ JMS broker using Spring Integration and Spring Boot.
A detailed step-by-step tutorial on how a Spring JMS listener works in combination with Spring Boot.
A detailed step-by-step tutorial on how to use JmsTemplate in combination with Spring JMS and Spring Boot.
A detailed step-by-step tutorial on how to implement a message selector using Spring JMS and Spring Boot.
A detailed step-by-step tutorial on how to implement a message converter using Spring JMS and Spring Boot.
A detailed step-by-step tutorial on how to use a Spring Boot admin UI to manage Spring Batch jobs.
A detailed step-by-step tutorial on how to implement a Spring Batch Tasklet using Spring Boot.
A detailed step-by-step tutorial on how to implement a Hello World Spring Batch job using Spring Boot.
Let's take a look on the samples howto use that based on ActiveMQ JMS.
https://bitbucket.org/tomask79/spring-integration-java-dsl/src/master/
1.spring integration 's architecture
ä¸»è¦æä¾›ä¸¤ä¸ªåŠŸèƒ½åQ?/p>
在系¾lŸå†…æä¾›å®žçŽ°è½»é‡¾U§ã€äº‹ä»‰™©±åŠ¨äº¤äº’è¡Œä¸ºçš„æ¡†æž¶
在系¾lŸé—´æä¾›ä¸€¿U基于适é…器的òq›_°åQŒä»¥æ”¯æŒç‰|´»çš„ç³»¾lŸé—´äº¤äº’
2.spring integration对于ä¼ä¸šé›†æˆæ¨¡å¼çš„æ”¯æŒ?/p>
2.1MessageåQšä¸€ä¸ªä¿¡æ¯çš„å•å…ƒåQŒé€šå¸¸æœ‰æ¶ˆæ¯å¤´åQˆheaderåQ‰å’Œæ¶ˆæ¯å†…容åQˆpayloadåQ‰ç»„æˆ?/p>
2.2Message channelåQšæ¶ˆæ¯å¤„ç†èŠ‚ç‚¹ä¹‹é—´çš„˜qžæŽ¥åQŒè´Ÿè´£å°†Messageä»Žç”Ÿäº§è€…ä¼ è¾“åˆ°æ¶ˆè´¹è€…ã€?/p>
æ ÒŽ®æ¶ˆè´¹è€…的多少åQŒå¯åˆ†äØ“point to pointå’Œpublish-subscribe两ç§
æ ÒŽ®æ¶ˆæ¯ä¼ 输方å¼çš„ä¸åŒï¼Œåˆ†äØ“åŒæ¥å’Œå¼‚æ¥ä¸¤¿U?/p>
2.3Message EndpointåQšæ¶ˆæ¯å¤„ç†èŠ‚ç‚¹ï¼Œæ¶ˆæ¯ä»ŽèŠ‚ç‚¹è¿›å…¥é€šé“åQŒä¹Ÿæ˜¯ä»ŽèŠ‚ç‚¹¼›Õd¼€é€šé“
å‡ ä¸ªå¸¸è§çš„Message EndPointåQ?/p>
CHANNEL ADAPTERåQŒç”¨äºŽè¿žæŽ¥è¯¥é€‚é…器的特点是å•呿¶ˆæ¯æµçš„,è¦ä¹ˆæ˜¯æ¶ˆæ¯é€šè¿‡è¯¥é€‚é…器进入通é“åQŒè¦ä¹ˆæ˜¯æ¶ˆæ¯é€šè¿‡è¯¥é€‚é…器离开通é“
MESSAGING GATEWAYåQŒå¤„ç†çš„æ¶ˆæ¯‹¹å’ŒChannel Adapterä¸åŒåQŒä¸æ˜¯å•å‘çš„åQŒå³æœ‰è¿›å…¥è¯¥èŠ‚ç‚¹çš„æ¶ˆæ¯ï¼Œä¹Ÿä¼šä»Žè¯¥èŠ‚ç‚¹å‘出消æ¯ã€?br />
SERVICE ACTIVATORåQŒè¯¥èŠ‚ç‚¹è°ƒç”¨æœåŠ¡æ¥å¤„ç†è¾“入的消æ¯åQŒåƈž®†æœåŠ¡è¿”å›žçš„æ•°æ®å‘é€åˆ°è¾“出通é“。在spring integrationä¸ï¼Œè°ƒç”¨çš„æ–¹æ³•被é™å®šä¸ºæœ¬åœ°æ–¹æ³•调用ã€?br />
ROUTERåQŒèµ\由器åQŒå°†è¾“入的消æ¯èµ\由到æŸä¸ªè¾“出通é“ä¸?/p>
SPLITTERåQŒå°†è¾“å…¥çš„æ¶ˆæ¯æ‹†åˆ†æˆå消æ?br />
AGGREGATORåQŒå°†è¾“入的多个消æ¯åˆòq¶äؓ一个消æ?br />
3.观看书ä¸ä¾‹åhello-worldæ€è€?/p>
‹¹‹è¯•gatewayæ—Óž¼Œä¸‹é¢ä»£ç å‘通é“names内放入消æ¯worldåQ?/p>
ç„¶åŽservice-activator从names通é“ä¸èŽ·å¾—æ¶ˆæ¯worldåQŒè°ƒç”¨æ–¹æ³•sayHello˜q”回值到¾l™gatewayåQ?/p>
解释åQšgateway有一个serviceåQinterface的属性,˜q™ä¸ªå±žæ€§æŒ‡å‘一个interface。当我们用一个接å£å£°æ˜Žä¸€ä¸ªgatewayæ—Óž¼Œspring integration会自动帮我们生æˆè¯¥æŽ¥å£çš„代熾c»ï¼Œ˜q™æ ·å½“我们往gatewayå‘逿¶ˆæ¯æ—¶åQŒspring integration会通过代熾cÀLŠŠæ¶ˆæ¯è½¬å‘到defaultåQrequeståQchannelä¸åŽ»