1

We have a requirement is to build spring boot command line applicarion where we have to send messages to queue.

Only request queue has been setup. As there is no response queue setup, we are not getting any acknowledgement from client side if they receive a message or not. Right now I am using Spring's JMSTemplate send() method to send message to request queue and SingleConnectionFactory to create one shared connection as this is commmand line application

As there is no acknowledgement/response to message we send to request queue, End to end testing is difficult. If destination/request queue connection is obtained and message is sent without any exception, I consider it a successful test.

Is it a right to implement Spring JMS templates send() method only ? and not following jms template send/receive pattern

Note: It is not possible to setup a response queue and get any acknowledgement from client side.

Priyanka
  • 13
  • 3
  • Asking questions about "better design" is really off-topic on Stack Overflow as it will lead to opinion-based answers and discussion rather than fact-based answers. I would encourage you to rephrase your question to be more specific and concrete. – Justin Bertram Apr 27 '21 at 01:34
  • Yes, but i have always seen jms templates with send-recive architecture in various project. So i wanted to check if design wise it is okay to implement only send functionality – Priyanka Apr 27 '21 at 05:26
  • Then you should make that more clear in your question. Again, asking for a "better design" is off-topic. – Justin Bertram Apr 27 '21 at 13:16
  • edited the question as per your suggestion – Priyanka Apr 27 '21 at 18:33

1 Answers1

0

In JMS (and in most other messaging systems) producers and consumers are logically separated (i.e. de-coupled). This is part of the fundamental design of the system to reduce complexity and increase scalability. With these constraints your producers shouldn't care whether or not the message is consumed. The producers simply send messages. Likewise, the consumers shouldn't care who sends the messages or how often, etc. Their job is simply to consume the messages.

Assuming your application is actually doing something with the message (i.e. there is some kind of functional output of message processing) then that is what your end-to-end test should measure. If you get the ultimate result you're looking for then you may deduce that the steps in between (e.g. sending a message, receiving a message, etc.) were completed successfully.

To be clear, it's perfectly fine to send a message with Spring's JMSTemplate without using a request/response pattern. Generally speaking, if you get no exceptions then that means the message was sent successfully. However, there are other caveats when using JMSTemplate. For example, Spring's JavaDoc says this:

The ConnectionFactory used with this template should return pooled Connections (or a single shared Connection) as well as pooled Sessions and MessageProducers. Otherwise, performance of ad-hoc JMS operations is going to suffer.

That said, it's important to understand the behavior of your specific JMS client implementation. Many implementations will send non-persistent JMS messages asynchronously (i.e. fire and forget) which means they may not make it to the broker and no exception will be thrown on the client. Sending persistent messages is generally sufficient to guarantee that the client will throw an exception in the event of any problem, but consult your client implementation documentation to confirm.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • We prepare a message using some business logic and send it to queue. No processing will be done on the acknowledgement/response/output message received by the consumers. Acknowledgement is just to make sure that consumser receives the message and acknowledges same. So what i understand is, in our specific case, we can use JMS template send method only ( as only request queue is available ) and for end to end test we can check if message is sent to queue without any exception. Is it correct ? – Priyanka Apr 27 '21 at 05:42
  • So you're sending a message that gets consumed, but the consumers don't actually do anything with the message? – Justin Bertram Apr 27 '21 at 13:15
  • No, we send messages that gets consumed, but if we get response/acknowledgement back from the consumer for message we send that consumer received it, that acknowledgment we will not use further. so is itnokay to implement jms template send mechanism only? – Priyanka Apr 27 '21 at 18:23
  • I updated my answer to address your comment. I hope that helps. – Justin Bertram Apr 27 '21 at 19:22