functional testing a JMS message queue with JMeter - jms

I've got a REST service that in response to a request, posts a message on a JMS queue. All of the main http functional testing is done using JMeter, so I was wondering if anyone has successfully pulled a JMS message off an existing queue in JMeter?

JMeter will do no such thing, but a class that you write to extend MessageListener, register with the queue, and have JMeter instantiate in a JUnit test certainly can. I'd recommend that you keep the consuming and testing separate. Write that MessageListener, get it working, and then figure out how to wire it into JMeter.

Related

JMeter - IBM MQ - Connections Issue

We have been doing performance testing of an application that uses IBM MQ. Through JMeter we are injecting the payload via a JMS Publisher. However, when running the test it can be observed that the connections from the JMeter threads are not being released. This effects the ability to reach the throughput and test failure due to the accumulation of threads. Is there a better alternative than using the JMS Publisher? Or is there setting there that needs to be enabled in order to release the connection once the request has been sent?
https://www.blazemeter.com/blog/ibm-mq-tutorial - Is this the best practice to implement testing IBM MQ?
What are you trying to achieve? JMeter implements Object Pool Pattern so each JMeter thread (virtual user) creates its own JMS connection and on subsequent iterations of the JMS Publisher sampler the Publisher object is being returned from the pool rather than created from zero.
If this is not something you want (or not how your JMS application acts) and you would like to close the connection after posting a message to queue/topic you can achieve it quite easily using JSR223 PostProcessor and the following Groovy code:
def publisher = sampler.publisher
org.apache.jmeter.protocol.jms.client.ClientPool.removeClient(publisher)
org.apache.commons.io.IOUtils.closeQuietly(publisher, null)
sampler.publisher = null

JMS with Spring Integration or Spring Batch

Our project is to integrate two applications, using the REST API of each and using JMS (to provide asynchronous nature). Application-1 writes the message on the queue. The next step is to read the message from the queue, process it, and send it to application2.
I have two questions:
Should we use one more queue for storing messages after processing and before sending them to application2?
Should we use spring batch or spring integration to read/process the data?
Or you don't show the whole premise, or you really try to overhead your app. If there is just need to read messages from the queue, there is just enough to use Spring JMS directly... From other side with the Spring Integration and its Adapters power you can just process messes from the <int-jms:message-driven-channel-adapter> to the <int-http:outbound-channel-adapter>.
Don't see reason to store message somewhere else in the reading and sending process. Just because with some exception here you just rollback your message to the JMS queue back.

Spring-boot app displaying JMS messages on WebPage via WebSocket

I need a simple web-app in spring-boot that listens for messages on a JMS queue and when arriving it should appear on a webpage via WebSocket.
I have searched for examples and found several individual; either WebSocket or JMS which I have tested on their own but have not succeeded in wiring it together.
I have searched for an example but not found any and in my mind I think it should be pretty easy since it's a very basic requirement.
Do you know about any example with JMS and HTML display via WebSocket that you can share or can give some hints or help for me to solve it?
The Spring Integration comes to the rescue.
You can write <int-jms:message-driven-channel-adapter> to read messages from JMS queue and forward them to the <int-websocket:outbound-channel-adapter>. Where the last one just sends messages to the connected WebSocket session(s).
See these Spring Integration samples on the matter:
https://github.com/spring-projects/spring-integration-samples/tree/master/basic/jms
https://github.com/spring-projects/spring-integration-samples/tree/master/basic/web-sockets
UPDATE
To send the message to all subscribed WebSocket session you should do something like this:
<int:splitter input-channel="enricheMessage" output-channel="sendMessage" apply-sequence="false">
<int-groovy:script>
#serverWebSocketContainer.sessions.keySet().collect {
org.springframework.integration.support.MessageBuilder.withPayload(payload)
.copyHeaders(headers)
.setHeader('simpSessionId', it)
.build()
}
</int-groovy:script>
</int:splitter>
With this Groovy script I retrieve session ids from the serverWebSocketContainer (all those connected clients), iterate over them to build messages to send them over their websocket. And split finally, to send to the <int-websocket:outbound-channel-adapter> one by one.

Spring Integration handle http outbound gateway failures

There are multiple servers that are listening to activemq. The chain is configured to make the http [outbound gateway] call. Suppose one of the server picks up the message and in-between if the http call fails for some reason. The message should be put back to the queue, so that another server can pick up the message and process. Can this be achieved using Spring Integration. I read lot on Transaction, however unable to find workable way.
Yes, simply set acknowledge="transacted" on the <int-jms:message-driven-channel-adapter/> and, as long as you use only direct channels (no <queue/> on the channel or task-executor on the channel's dispatcher) then any failure will cause the message to roll back.

JMS request/reply pattern in grails

I am creating a grails web app which makes use of JMS messaging. I have installed the JMS plugin for grails and using activemq as the messaging provider. I want to implement a request/response pattern in grails.
I was successfully able to send a message to the queue using the
sendQueueJMSMessage("queueName",Map message) from a controller.
I then created a service which contains the onMessage() method that listens to the "queueName" as stated above.
The onMessage() method does some processing and successfully sends an email to the user.
The above scenario has been implemented successfully.
Now, I would like to receive a response from this onMessage() method.
Lets say I want to implement the below scenario.
The request is added to the queue and waits for a response. I looked around but I couldnt find any help.
Please give me a lead on this. I really appreciate it.
Spring JMS adds support for auto replies, which the Grails plugin supports. See: http://gpc.github.com/grails-jms/docs/manual/guide/5.%20Receiving%20Messages.html#5.3%20Listener%20Return%20Values
Here is a test exercising this stuff: https://github.com/gpc/grails-jms/blob/master/test/integration/grails/plugin/jms/test/reply/ReplyingListenerServiceSpec.groovy#L12
The other option is to just send another message from your first message receiving method.
you did not provide much to work with here so the my suggestion is to take a look at the samples in the Grails JMS Plugin - Reference Documentation: 5. Receiving Messages, or provide some code

Resources