{"id":545,"date":"2010-12-08T11:22:34","date_gmt":"2010-12-08T09:22:34","guid":{"rendered":"http:\/\/mcl.jogger.pl\/2010\/12\/08\/easier-and-nicer-jms\/"},"modified":"2023-03-23T12:52:51","modified_gmt":"2023-03-23T11:52:51","slug":"easier-and-nicer-jms","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2010\/12\/08\/easier-and-nicer-jms\/","title":{"rendered":"Easier and nicer JMS"},"content":{"rendered":"<table border=\"0\">\n<tr>\n<td>\n<p>JMS seems like a hostile ground. It has all it&#8217;s quirks and strange behaviours. A couple of defining standards plus esoteric brokers, queues and topics.<\/p>\n<\/td>\n<td><img decoding=\"async\" src=\"http:\/\/blog.innovative-labs.com\/blog\/Screwdriver.jpg\" width=\"150\"><\/td>\n<\/tr>\n<\/table>\n<p>At work, we mainly use open source Jms solutions, namely Apache ActiveMQ. This one is usually bundled with Apache Servicemix, as a message broker for this particular ESB. As there are some minor caveats in this scennerio, I&#8217;d like to describe here some guidelines for getting to running JMS queues.<\/p>\n<p>Treat this post as a quick cheat sheet with the most common things about JMS I tend to forget :)<\/p>\n<p>Minor glitches encountered during work with embedded broker led to some thoughts about switching to external broker. This is how I configure SMX and AcviteMQ.<\/p>\n<p>Necessary steps:<\/p>\n<ul>\n<li>change <i>apache-servicemix\/conf\/servicemix.properties<\/i> <b>activemq.port<\/b> to sth else than standard, for example 61626<\/li>\n<li>change <i>apache-activemq\/conf\/activemq.xml<\/i> with this settings:\n<ul>\n<li>change port, the service listens on:\n<pre class=\"brush: xml\">\r\n        \r\n            \r\n        \r\n<\/pre>\n<\/li>\n<li>setup separate JMX instance:\n<pre class=\"brush: xml\">\r\n        \r\n            \r\n        \r\n<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>the nicest tool I found for browsing queues and topics is <a href=\"http:\/\/www.hermesjms.com\">Hermes JMS<\/a>. Sample config, that connects Hermes to ActiveMQ instance is on the picture below: <img decoding=\"async\" src=\"http:\/\/blog.innovative-labs.com\/blog\/easy_jms.png\" width=\"550\" alt=\"HermesJMS to ActiveMQ connection config\"><\/li>\n<li>sending simple messages with Hermes is basic, but what if you need to set some headers, send bulk messages, etc. Easy, just use Hermes xml format. Look like this code snippet below and is rather self-explanatory:\n<pre class=\"brush: xml\">\r\n\r\n    \r\n        \r\n            \r\n            \r\n&lt;![CDATA[\r\n  \r\n    \r\n      105\r\n      1235\r\n    \r\n  \r\n]]&gt;\r\n\r\n        \r\n    \r\n\r\n<\/pre>\n<\/li>\n<li>since we use lots of <a href=\"http:\/\/camel.apache.org\">Apache Camel<\/a> to consume messages, here is a simple way to start broker in your tests:\n<ul>\n<li>start a broker\n<pre class=\"brush: java\">\r\n        BrokerService broker = new org.apache.activemq.broker.BrokerService();\r\n        broker.setBrokerName(\"AMQ-1\");\r\n        broker.addConnector(\"tcp:\/\/localhost:51616\");\r\n        broker.setPersistent(false);\r\n        broker.start();\r\n<\/pre>\n<p>Notice it has persistance disabled.<\/li>\n<li>initialize Camel&#8217;s JMS component:\n<pre class=\"brush: java\">\r\n    ctx.removeComponent(\"jms\");\r\n    ctx.addComponent(\"jms\", ActiveMQComponent.activeMQComponent(\"tcp:\/\/localhost:51616\"));\r\n<\/pre>\n<\/li>\n<li>if you want to pass messages to reference endpoints, (like <i>ref:input<\/i>), use this wrapper method:\n<pre class=\"brush: java\">\r\nprivate JmsEndpoint createJmsEndpoint(String endpoint) throws JMSException {\r\n        ActiveMQComponent amqc = (ActiveMQComponent) ctx.getComponent(\"jms\");\r\n        JmsEndpoint endp = JmsEndpoint.newInstance(new ActiveMQTopic(endpoint), amqc);\r\n        return endp;\r\n}\r\n\r\ncreateJmsEndpoint(\"ESB\/XYZ\")\r\n<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>These are all the tricks I&#8217;ve got for now! But if you know some other good tools that handle JMS, feel free to comment! Got more advices, again, comment!<\/p>\n","protected":false},"excerpt":{"rendered":"JMS seems like a hostile ground. It has all it&#8217;s quirks and strange behaviours. A couple of defining&hellip;\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[186],"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/545"}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=545"}],"version-history":[{"count":8,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/545\/revisions"}],"predecessor-version":[{"id":15615,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/545\/revisions\/15615"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}