Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p> This page is under construction.</p> <h1>Basic Operations</h1> <h2>Objects</h2> <h3>JMS</h3> <h3>JMSPool</h3> <ul> <li>Constructor arguments, refer to the <a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html#constructor_summary">JavaDoc of ThreadPoolExecutor</a> <ul> <li>corePoolSize: 10, maximumPoolSize: 20, keepAliveTime: 360, unit: TimeUnit.MILLISECONDS</li> </ul> </li> </ul> <h2>APIs</h2> <h3>receive()</h3> <ul> <li>for a queue, receive is the standard JMS receive method.</li> <li>for topics, the receive() method is a blocking operation that create a 'temporary subscription'. The 'temporary subscription' wait for the first message and then unsubscribe and return the message. If a 'within' expiry time is provided, the 'temporary subscription' will be unsubscribed when the 'within' time is reached, and return null. This feature is typically used with message selector, and is useful for simulating a synchronous operation with the asynchronous JMS infrastructure. e.g. a client use a new thread to send a request with some delay, and in the main thread listen to the server response topic in synchronous manner. <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def pool = new JMSPool() pool.send toQueue:'chatService',message:\[user:'groovy100',room:100\],delay:500 //it sends a message in another thread, the delay is avoid getting a result before the subscribed to the topic def result = pool.receive fromTopic:'signedOnBroadcast',messageSelector:"newUser = 'groovy100'" if (result) // you have successfully signed on else // retry? or tell user to sign in again. </pre></td></tr></table></li> </ul> <h2>Shared Features</h2> <p>Features that are used across APIs are listed in this section</p> <h3>Message Selector</h3> <ul> <li>In JMS, Message Selector is a String that defines some filtering conditions for receiving messages. Refer to the <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html">JMS Javadoc</a> for details</li> <li>In Groovy Messaging Service API, you may use the messageSelector parameter in receive and onMessage,the message selector parameter takes a String, a List, a Map, or a Closure with one parameter <ul> <li>For a String, the String will be used for every destination specified in the same call</li> <li>For a List, it will be matched a against the List of Queue and Topic respectively. If the number of destination is less than the number of message selector items, the excess message selectors will be ignored. If the number of destination is more than the number of message selector items, the excess destination will have no message selector. You could use null for destination or message selector in doing matching. When both fromQueue and fromTopic are used, the two list of destinations will be muched respectively with the same list of message selector.</li> <li>For a Map, the key of the map parameter will be matched against the destination name.</li> <li>For a Closure, it works similar to a map and it passes in the destination name or destination and expect a String of return value as the message selector</li> </ul> </li> </ul> <h2> </h2> <h1>Advanced Features</h1> <h2>JMSPool</h2> <h3>Overview</h3> <ul> <li>JMSPool is an advanced JMS instance that allow multiple threading messaging for incoming and outgoing messages. It is built on Java 5 concurrency library and also utilize the ActiveMQ Pooled Connection Factory. So only Java 5 and AMQ are supported.</li> <li>For simple JMS usage, <ul> <li>a new connection and session are created on every JMS execution block. Resources are closed after usage.</li> <li>user has to manage threads and concurrency. Without special coding, messages are sent and received in a single connection and session. </li> </ul> </li> <li>The currently JMSPool is fairly simple. It does not support features like transaction, connection recovery etc. If you need a full feature JMS Pooling product, you are highly recommended to use Spring JMS or Jencks.</li> <li>With JMSPool <ul> <li>You could use a JMSPool intance with multiple threads for incoming and outgoing messaging</li> <li>The threads are managed by Java 5 ThreadExecutor</li> <li>Each thread uses a JMS instance</li> <li>All closure in any thread are run in the use(JMSCategory){ } context. i.e. you could freely use GroovyJMS APIs</li> </ul> </li> </ul> <h3>Outgoing messages (jms.send())</h3> <ul> <li>For outgoing messages to Queue or Topic, it works like the following diagram <table class="confluenceTable"><tbody> <tr> <td class="confluenceTd"><p> <img class="confluence-embedded-image image-left" src="/download/attachments/230400676/jmspool-outgoing.png?version=1&modificationDate=1368929835359" data-image-src="/download/attachments/230400676/jmspool-outgoing.png?version=1&modificationDate=1368929835359" data-linked-resource-id="230565062" data-linked-resource-type="attachment" data-linked-resource-default-alias="jmspool-outgoing.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="230400676" title="null > jmspool-outgoing.png"> </p></td> </tr> </tbody></table> <ul> <li>Without the pool, multiple clients will have to send message in a serial manner. The JMSPool supports clients from multiple threads to send message asynchronously. When there are more concurrent message than worker threads, the messages will be put on a an internal buffer.</li> <li>Worker threads are spawn to handle connection in parallel, each thread makes a connection to the JMS server.</li> <li>In the initial implementation, the main advantage of the JMSPool over the original JMS are: <ul> <li>user could easily send outgoing message in parallel, e.g. <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def pool = new JMSPool(maximumPoolSize:10) 10.times{ pool.send toQueue:'testQueue', message:"this is message #$it"} </pre></td></tr></table> It spawns 10 threads to send 10 messages in parallel.</li> <li>Asynchronous sending<br /> every user call is returned asynchronously after it reaches the internal buffer, instead of waiting for the message to reach the external JMS server. It potentially provide a better throughput when you have a large volume of messages to send. Notice that this is not necessary the ideal behavior in every case and you should be cautious when using it, and <strong>without a recovery mechanism in place (as in the initial implementation), your outgoing message may lose</strong> if there is exception in delivery and you'll only get an exception via the global exception handler. <strong>TODO</strong> verify the exception implementation</li> <li>connection reuse<br /> every thread get a connection from the AMQ connection pool to send message. The connection pool is supposed to provide connection re-use. Session is not shared.</li> <li>parallel messaging for multiple destination <strong>(NOT implemented yet)</strong> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def pool = new JMSPool(maximumPoolSize:10) pool.send toQueue:['queue0', 'queue1'], toTopic:'topic0', message:"a msg for 3 dest", threads:3} // or threads:'auto' </pre></td></tr></table> A single send operation is split to three threads, and the message is sent in parallel. The number of threads should be less than the maximumPoolSize.</li> </ul> </li> </ul> </li> </ul> <h3>Async incoming message</h3> <ul> <li>Diagram <table class="confluenceTable"><tbody> <tr> <td class="confluenceTd"><p> <img class="confluence-embedded-image image-left" src="/download/attachments/230400676/jmspool-async_incoming.png?version=1&modificationDate=1368929835375" data-image-src="/download/attachments/230400676/jmspool-async_incoming.png?version=1&modificationDate=1368929835375" data-linked-resource-id="230565063" data-linked-resource-type="attachment" data-linked-resource-default-alias="jmspool-async_incoming.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="230400676" title="null > jmspool-async_incoming.png"> </p></td> </tr> </tbody></table> </li> <li>JMSPool assumes you want to use one thread per "destination and message selector" in each call. (<strong>TODO: message selector is not implemented</strong>) When there are multiple destination and message selector combination,</li> <li>onMessage allows user to receive messages one by one in an asynchronous basis. It works differently depends on the destination: <ul> <li>for a queue, multiple threads will be spawn with the same listener to the queue. As messages are received one by one per thread. You are able to receive messages at a much higher rate.</li> <li>for a topic, it doesn't make sense to subscribe with more than one thread. So the threads parameter will be ignored.</li> <li>for multiple queues and topics, every queue will be listened by the specified number of threads, and every topic will be subscribed by one thread only. (as the 'threads' parameter is ignored)</li> </ul> </li> <li> TODO: perhaps the 'threads' parameter could be implemented in a way similar to Message Selector and take a list or map of value</li> </ul> <h3>Sync receive message</h3> <ul> <li>synchronous message receiving, e.g. jms.receive fromQueue:"myQueue, works very similar to its asynchronous counterpart. But behave differently in the following ways: <ul> <li>when the receive method is used to receive all messages (it is by default if a 'limit' parameter is not used), there is no real need to use multiple thread and it may not improve performance unless you have a lot of messages. The 'threads' parameter will be honored and you should use it according to your need.</li> <li>For queues, when multiple threads are used, it waits for every thread to complete their works, and aggregate all results to return to you. The 'with' closure for queue will be called once and only once with the aggregated result in the first parameter.</li> <li>For topics, only one thread will be used for each topic-selector pair. When the number of topic-selector pairs is less than the number of 'threads', e.g. fromTopic:['t0','t1','t2'], threads:2, a 'temporary subscription' will be issued for the first 2 topics immediately, and only after one of them has return, a 'temporary subscription' will be issued for the 3rd topic. And only after all 3 topics are done, you'll get the aggregated return value.</li> </ul> </li> </ul>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced