how to subscribe jms in other program? - spring

I try to make example project using spring and jms.
so, I refer a site(https://spring.io/guides/gs/messaging-jms/).
However, when i run the server, i don't know how to subscribe message in the other program.
please give me some hint.

If you look at the code, author has used destination name as - "mailbox-destination". When you need to receive a message, you need to listen to the same destination. Author has also given the code of Receiver. Please take a look at src/main/java/hello/Receiver.java.
You will need the same code in other application to receive the message. If you would like to try some more examples, take a look at :
receive message using direct message listener
receive message using message listener adapter

Related

Restrict incoming message signature for message broker

My goal is to define some API using REST arch style and spring boot in order to store messages to activemq message broker. I would like to have REST on top of message broker to have possibility to restrict message format. Actually the main goal is to allow only messages which contains all nessessary fields inside message payload.
Could you please suggest if it is rigth way to go and if there are any alternative ways to achive the goal?
Yes. This is a REST-to-Messaging Proxy design and can work just fine for the use case you described.
Alternatively, you could do the message inspection in the broker, but since this inspection sounds logic-related, it is best suited for something running outside the broker.

Not able to push message to one of the queue silently failing, at the same time able to send to other queues

I am trying to put message to Azure service bus queue, and using QueueClient to send the message. But it is not sending message to queue. But it is not even giving any error or exception. It is silently failing not sure what is going wrong here.
queueClient.Send(message);
This line is not throwing exception but not even sending message for Q1, but able to send message to Q2 in same service bus namespace.
QueueClient is from Microsoft.ServiceBus.Messaging.QueueClient.
Thanks
Please check out whether there is any autocomplete option enabled because if there is no exception or any error then it might be the problem. Also, check whether you have used any autocomplete function. If it so, that function would delete all of your message and remove it.

Processing a single message using Spring jms

I am working on an existing Spring jms application that pulls messages from ActiveMQ using jms:inbound-gateway. This application is a job processor that takes jobs off a queue and sends results back to the queue. Everything currently works great.
I would like to modify this application to accept one and only one job, process it, and then exit, but I have not been able to find a way to cleanly do this. The method that is called must return the results, and the results are automatically placed back onto the queue by Spring. Is there any way to tell Spring to stop accepting messages at 1? How would you know when it's done sending the reply message so you can exit.
In a more general case, if you had an application that wanted to stop accepting messages and finish processing them all so you could exit cleanly, how can that be done?
Thanks in advance for any advice.
It sounds like you should be using JmsTemplate.receive . Inbound gateway is meant for a message driven model. It sounds like while you are using a message queue for transport, you're not really doing a message driven model of processing. Obviously that's not a problem but if your aim is to process a single message you should just use JmsTemplate.
Another way to do this is to use the default message listener container, ensure threads is set to one and then make sure your activemq setup has no read-ahead setup (i.e. reads one message at a time and no more). Then, at the end of your onMessage method, call the DMLC.stop method.

MQPUT while using MQCB : MQRC_HCONN_ASYNC_ACTIVE

Our process needs to read messages from a topic on the local Q manager and also write to a different topic on the same local Q manager.
To read messages we have used MQCB. The messages reach the callback function of the process. However, while the callback remains registered, we are not able to MQPUT messages to a different topic.
We get an error that says:
2500 : MQRC_HCONN_ASYNC_ACTIVE
An attempt to issue an MQI call has been made while the connection is started
Apparently, a single connection handle cannot be used to both read and write. We have to Suspend the MQCB, MPUT the message and Resume the MQCB to get it to work.
Is there a way to avoid having to suspend and resume?
Thanks in advance
Yes, that is the expected behavior when using MQCB. Two approaches you can take:
1) Create another connection to the same queue manager to publish messages.
2) If your design is to publish messages whenever you receive a message on the callback function, then publish messages from callback function itself.
Update
MQRC_ALREADY_CONNECTED (2002) issue: What MQCNO_HANDLE_SHARE_* option have you used? Suggest you to use MQCNO_HANDLE_SHARE_BLOCK option to get around this problem. I wrote a sample program and created two connections on the same thread by using MQCNO_HANDLE_SHARE_BLOCK option.

Spring integration - message store recovery/resend

I have a question regarding the behavior of a jdbc message store. I notice that if a failure occurs for instance if the following sequence is followed:
1)inbound-channel-adapter - Creates a message payload and sends it to a channel
2)The channel is polled for the payload by a jms:outbound-channel-adapter which adds an entry in the JMS queue. I am using ActiveMQ.
When I test for a situation like shutting down the MOM I would like to persist the message in the message-store, but this is not the default behavior. Looks like SI processes the payload in the channel and then pushes it out (deletes it from the store). I can see the message being inserted in the message-store in the database.
Am I wrong in understanding the function of a message-store? I thought that the message would persist until a successful run. Thanks for any feedback.
You need to set up durable subscriptions for that. I think most of the SI JMS components do support that.

Resources