{"id":9129,"date":"2023-01-14T09:05:41","date_gmt":"2023-01-14T01:05:41","guid":{"rendered":"http:\/\/123.57.164.21\/?p=9129"},"modified":"2023-03-15T17:26:03","modified_gmt":"2023-03-15T09:26:03","slug":"apache-camel-%e5%92%8cibm-mq%e7%9a%84tips","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=9129","title":{"rendered":"Apache Camel \u548cIBM MQ\u7684Tips"},"content":{"rendered":"\n<p>Apache Camel \u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u548cIBM MQ\u8fdb\u884c\u901a\u4fe1\uff0c\u4e0b\u9762\u662f\u4e00\u4e9bTips\u3002<\/p>\n\n\n\n<p><strong>1.IBM MQ \u5b89\u88c5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Docker\u5b89\u88c5IBM MQ\uff08\u6ce8\u610f \u955c\u50cf\u4e0d\u652f\u6301M1\u82af\u7247\u7684Mac\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\u4e0b\u8f7d \u955c\u50cf\n docker pull ibmcom\/mq:9.2.4.0-r1\n\n#\u8fd0\u884c\u5bb9\u5668\n docker run  --name ibmmq -p 1414:1414  -p 9443:9443 -e LICENSE=accept  -e MQ_QMGR_NAME=QM1  -e MQ_APP_PASSWORD=passw0rd -d ibmcom\/mq:9.2.4.0-r1<\/pre>\n\n\n\n<p><strong>2.IBM MQ\u306e\u7ba1\u7406\u9875\u9762<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">https:\/\/ip host\u5730\u5740:9443\/ibmmq\nusername: admin\npassword: passw0rd<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/01\/image-2-1024x489.png\" alt=\"\" class=\"wp-image-9131\" width=\"505\" height=\"242\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-1024x489.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-300x143.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-768x367.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-1536x734.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-2048x978.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-830x396.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-230x110.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-350x167.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-2-480x229.png 480w\" sizes=\"(max-width: 505px) 100vw, 505px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/01\/image-3-1024x600.png\" alt=\"\" class=\"wp-image-9132\" width=\"500\" height=\"293\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-1024x600.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-300x176.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-768x450.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-1536x900.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-2048x1200.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-830x486.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-230x135.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-350x205.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-3-480x281.png 480w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/figure><\/div>\n\n\n\n<p><strong>3.Camel Maven\u5de5\u7a0b IBM MQ Pom\u5bfc\u5165<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;dependency>\n    &lt;groupId>org.apache.camel&lt;\/groupId>\n    &lt;artifactId>camel-jms&lt;\/artifactId>\n    &lt;scope>provided&lt;\/scope>\n&lt;\/dependency>\n&lt;dependency>\n    &lt;groupId>com.ibm.mq&lt;\/groupId>\n    &lt;artifactId>com.ibm.mq.allclient&lt;\/artifactId>\n    &lt;version>9.1.0.5&lt;\/version>\n&lt;\/dependency><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/01\/image-4-1024x620.png\" alt=\"\" class=\"wp-image-9134\" width=\"530\" height=\"320\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4-1024x620.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4-300x182.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4-768x465.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4-830x503.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4-230x139.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4-350x212.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4-480x291.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-4.png 1030w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/figure><\/div>\n\n\n\n<p><strong>4.Camel \u5de5\u7a0b\u4e2d Spring DSL (XML) Sample<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n    xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n    xsi:schemaLocation=\"\n        http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\n        http:\/\/camel.apache.org\/schema\/spring http:\/\/camel.apache.org\/schema\/spring\/camel-spring.xsd\">\n\n    &lt;!-- \u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u5b9a\u7fa9 -->\n    &lt;bean id=\"mqConnectionFactory\" class=\"com.ibm.mq.jms.MQConnectionFactory\">\n        &lt;property name=\"hostName\" value=\"123.57.164.21\" \/>\n        &lt;property name=\"port\" value=\"1414\" \/>\n        &lt;property name=\"queueManager\" value=\"QM1\" \/>\n        &lt;property name=\"channel\" value=\"DEV.APP.SVRCONN\" \/>\n        &lt;property name=\"transportType\" value=\"1\" \/>\n        &lt;property name=\"shareConvAllowed\" value=\"0\" \/>\n    &lt;\/bean>\n\n    &lt;bean id=\"mqcredential\" class=\"org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter\">\n        &lt;property name=\"targetConnectionFactory\"\n            ref=\"mqConnectionFactory\" \/>\n        &lt;property name=\"username\" value=\"app\" \/>\n        &lt;property name=\"password\" value=\"\" \/>\n    &lt;\/bean>\n\n    &lt;bean id=\"mq\" class=\"org.apache.camel.component.jms.JmsComponent\">\n        &lt;property name=\"connectionFactory\" ref=\"mqcredential\" \/>\n        &lt;property name=\"maxConcurrentConsumers\" value=\"1\" \/>\n        &lt;property name=\"cacheLevelName\" value=\"CACHE_CONSUMER\" \/>\n    &lt;\/bean>\n\n    &lt;!-- \u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u5b9a\u7fa9 -->\n    &lt;routeContext id=\"route-1\"\n        xmlns=\"http:\/\/camel.apache.org\/schema\/spring\">\n        &lt;!-- \u30e1\u30a4\u30f3 -->\n        &lt;route id=\"mainroute-1\">\n            &lt;!--  \u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u8aad\u307f\u53d6\u308a  -->\n            &lt;from uri=\"mq:queue:DEV.QUEUE.1\"\/>\n            &lt;log loggingLevel=\"DEBUG\" message=\">>>${body}\" \/>\n            &lt;!--  \u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1 -->\n            &lt;to uri=\"mq:queue:DEV.QUEUE.2\"\/>\n        &lt;\/route>\n    &lt;\/routeContext>\n&lt;\/beans>\n<\/pre>\n\n\n\n<p><strong>5.\u4e00\u4e9b\u95ee\u9898<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"wp-block-preformatted\">JMSWMQ2013: \u4e3a\u961f\u5217\u7ba1\u7406\u5668\u201cQM1\u201d\u63d0\u4f9b\u7684\u5b89\u5168\u6027\u8ba4\u8bc1\u65e0\u6548\uff0c\u8fde\u63a5\u65b9\u5f0f\u4e3a\u201cClient\u201d\uff0c\u4e3b\u673a\u540d\u4e3a\u201c192.168.1.1(1415)\u201d\u3002 \u8bf7\u68c0\u67e5\u63d0\u4f9b\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u5728\u60a8\u8fde\u63a5\u81f3\u7684\u961f\u5217\u7ba1\u7406\u5668\u4e2d<\/pre>\n\n\n\n<p>\u5982\u679c\u51fa\u73b0\u8fd9\u4e2a\u9519\u8bef\uff0cQM1 \u961f\u5217\u7ba1\u7406\u5668\u3002\u5173\u95edCHLAUTH\u8bb0\u5f55<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/01\/image-5-1024x500.png\" alt=\"\" class=\"wp-image-9138\" width=\"503\" height=\"246\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-1024x500.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-300x146.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-768x375.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-1536x750.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-2048x1000.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-830x405.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-230x112.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-350x171.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-5-480x234.png 480w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">JMSCMQ0001: WebSphere MQ \u8c03\u7528\u5931\u8d25\uff0c\u5b8c\u6210\u4ee3\u7801\u4e3a\u201c2\u201d\uff08\u201cMQCC_FAILED\u201d\uff09\uff0c\u539f\u56e0\u4e3a\u201c2035\u201d\uff08\u201cMQRC_NOT_AUTHORIZED\u201d\uff09\u3002<\/pre>\n\n\n\n<p>\u7528\u8fd9\u4e2aapp\u8d26\u6237\u53bb\u8fde\u63a5<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/01\/image-6-1024x426.png\" alt=\"\" class=\"wp-image-9140\" width=\"533\" height=\"222\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-1024x426.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-300x125.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-768x320.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-1536x640.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-2048x853.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-830x346.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-230x96.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-350x146.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/01\/image-6-480x200.png 480w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    &lt;bean id=\"mqcredential\" class=\"org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter\">\n        &lt;property name=\"targetConnectionFactory\"\n            ref=\"mqConnectionFactory\" \/>\n        &lt;property name=\"username\" value=\"app\" \/>\n        &lt;property name=\"password\" value=\"\" \/>\n    &lt;\/bean><\/pre>\n\n\n\n<p><strong>6.\u8865\u5145Java DSL (Java\u8a00\u8a9e)sample<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>IBM MQ<\/strong> provides these messaging and queuing capabilities across multiple modes of operation: point-to-point ; publish\/subscribe. You can easily integrate with this messaging provider by using the camel JMSComponent by setting the <strong>MQQueueConnectionFactory<\/strong> properties either in configuration or using Java DSL.<\/p>\n\n\n\n<p>Let\u2019s check how to write a Java DSL class which defines the <strong>JmsComponent<\/strong> named \u201cmq\u201d which takes the <strong>MQQueueConnectionFactory<\/strong> from Class variable:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import org.apache.camel.component.jms.JmsComponent;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Primary;\nimport org.springframework.jms.connection.CachingConnectionFactory;\nimport org.springframework.jms.connection.JmsTransactionManager;\nimport org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter;\nimport org.springframework.transaction.PlatformTransactionManager;\nimport org.springframework.transaction.annotation.EnableTransactionManagement;\nimport com.ibm.mq.jms.MQQueueConnectionFactory;\nimport com.ibm.msg.client.wmq.WMQConstants;\n@Configuration\n@EnableTransactionManagement\npublic class JmsConfiguration {\n  private static final Logger LOG = LoggerFactory.getLogger(JmsConfiguration.class);\n  private String host = \"localhost\";\n  private int port = 1414;\n  private String queueManager = \"QM1\";\n  private String channel = \"DEV.APP.SVRCONN\";\n  private String username = \"app\";\n  private String password = \"\";\n  private long receiveTimeout = 2000;\n  @Bean\n  public JmsComponent mq() {\n    JmsComponent jmsComponent = new JmsComponent();\n    jmsComponent.setConnectionFactory(mqQueueConnectionFactory());\n    return jmsComponent;\n  }\n  @Bean\n  public MQQueueConnectionFactory mqQueueConnectionFactory() {\n    MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();\n    mqQueueConnectionFactory.setHostName(host);\n    try {\n      mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);\n      mqQueueConnectionFactory.setChannel(channel);\n      mqQueueConnectionFactory.setPort(port);\n      mqQueueConnectionFactory.setQueueManager(queueManager);\n    } catch (Exception e) {\n      LOG.error(e.getMessage(), e);\n    }\n    return mqQueueConnectionFactory;\n  }\n  @Bean\n  public UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter(\n      MQQueueConnectionFactory mqQueueConnectionFactory) {\n    UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter =\n        new UserCredentialsConnectionFactoryAdapter();\n    userCredentialsConnectionFactoryAdapter.setUsername(username);\n    userCredentialsConnectionFactoryAdapter.setPassword(password);\n    userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(mqQueueConnectionFactory);\n    return userCredentialsConnectionFactoryAdapter;\n  }\n  @Bean\n  @Primary\n  public CachingConnectionFactory cachingConnectionFactory(\n      UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter) {\n    CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();\n    cachingConnectionFactory.setTargetConnectionFactory(userCredentialsConnectionFactoryAdapter);\n    cachingConnectionFactory.setSessionCacheSize(500);\n    cachingConnectionFactory.setReconnectOnException(true);\n    return cachingConnectionFactory;\n  }\n  @Bean\n  public PlatformTransactionManager jmsTransactionManager(\n      CachingConnectionFactory cachingConnectionFactory) {\n    JmsTransactionManager jmsTransactionManager = new JmsTransactionManager();\n    jmsTransactionManager.setConnectionFactory(cachingConnectionFactory);\n    return jmsTransactionManager;\n  }\n}<\/pre>\n\n\n\n<p>In order to use the <strong>JMSComponent<\/strong>, you can implement a simple Route like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import org.apache.camel.builder.RouteBuilder;\nimport org.springframework.stereotype.Component;\n@Component\npublic class CamelRouteBuilder extends RouteBuilder {\n  public void configure() throws Exception {\n    from(\"timer:mytimer?period=5000\")\n        .routeId(\"generate-route\")\n        .transform(constant(\"HELLO from Camel!\"))\n        .to(\"mq:queue:DEV.QUEUE.1\");\n  }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Apache Camel \u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u548cIBM MQ\u8fdb\u884c\u901a\u4fe1\uff0c\u4e0b\u9762\u662f\u4e00\u4e9bTips\u3002 1.IBM MQ \u5b89\u88c5 D [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9129"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9129"}],"version-history":[{"count":10,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9129\/revisions"}],"predecessor-version":[{"id":9917,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9129\/revisions\/9917"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}