Content on this page is under development, check the following email thread for the time being: http://www.nabble.com/Groovy-JMS-Category-td19861454.html
Design Requirement
- API must be in Groovy-style
- use typical Groovy syntax like with, each etc.
- sounds like English language
- Follow JMS concept and keywords, but need to to use exact name and API
- Simple and Easy to use
- Thread-safety
- JMS resource re-use and direct JMS usage
- Allow provision of ConnectionFactory, Connection or Session for reuse.
- Return sensible JMS resource for reuse or keeping reference
AS-IS, v0.1 release
- assumed to be start with a user provided JMS ConnectionFactory named "jms". In future release, this should not be required.
Type |
JMS Usage (In Groovy Syntax with Static Type for clarity) |
Proposed/Current API |
Reference |
|---|---|---|---|
Create Connection |
Connection conn = jms.createConnection() |
jms.connect() |
v0.1 |
Create Session |
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE) |
jms.session() |
v0.1 |
Create Topic |
Topic topic = session.createTopic("testTopic"); |
jms.topic("testTopic") |
v0.1 |
Subscribe to Topic |
TopicSubscriber subscriber = session.createDurableSubscriber(topic, "sub-name") |
topic.subscribe( {} as MessageListener ) |
v0.1 |
|
|
|
|
Groovy SQL-style API
Content in this section is moved to GroovyJMS Docs
Proposed
- Create
- jms.createQueue withName: "replyQueue"
- Queue replyQueue = jms.createQueue("replyQueue")
- Topic subscription
- jms.subscribeTo topic/ subscribe toTopic: "greeting", withListener/with:{ Message m -> println "hey i got a message. it says, '\${m.text}'" }
- jms.subscribe toTopic: "greeting", onMessage:{ Message msg -> println "hey i got a message. it says, \$
Unknown macro: {m.text}" }
- jms.subscribe("greeting"){println "hey i got a message. it says, \$
Unknown macro: {it.text}'"}
- jms.subscribe("greeting") { println "hey i got a message. it says, '\${m.text}'"
- Queue receive
- jms.receiveMessage fromQueue: "greeting", withinTimeoutOf: 1000
jms.receiveMessage/receive fromQueue: "greeting", within: 1000.ms
jms.receiveAllMessages/receiveAll fromQueue: "greeting", within: 1000.ms - jms.receiveMessage fromQueue: "greeting", within: 1000.ms, withMessage:
Unknown macro: { Message msg -> reply withTextMessage}
- jms.receive ("greeting", within: 1000.ms)
Unknown macro: { reply "hey, let me tell you secretly" }
- jms.receiveMessage fromQueue: "greeting", withinTimeoutOf: 1000
- Send message
- jms.send textMessage: "hey, please reply to me privately", onQueue: "greeting", withAttributes: [JMSCorrelationID: 'privatePlease', JMSReplyTo: replyQueue]
- jms.send message: "hey, please reply to me privately",
onQueue: "greeting",
JMSCorrelationID: 'privatePlease', JMSReplyTo: replyQueue - jms.send "hey, please reply to me privately",
onQueue: "greeting",
JMSCorrelationID: 'privatePlease', JMSReplyTo: replyQueue - When handling the closure, you could set a delegate to it, so that
methods like reply() would be delegated to the jms instance.
Also, passing the message in parameter of the closure, you can have
access to it, to deal with it, and use some of its attributes or text
body in your own replies.
Latest:
- JMS Connection Factory
- use a combination of Category and Builder to do the job.
- Use builder/closure rather than Category | use xxxx and xxxTo in two styles