JAX-WS best way to handle timeout - java

I'm using jax-ws with Spring. The client is a JMS consumer application that will make a call to the server to do some additional processing including sending an email. One situation that I have failed to handle is if a message comes through the consumer while the "server" application is restarting. Right now the client will just timeout and the message will not be fully processed. Any thoughts?

Setup a dead letter queue in which you'll place messages / web service requests that fail to be processed for some reason. You can now develop a scheduled service that will poll the dead letter queue at interval to retry sending the message.
Be sure to have setup your client to timeout gracefully (see this answer for details on timeout config) and use a persistent store (file/db) for your dead letter queue

Related

QuickFIX/J: How to handle inbound/outbound message in Initiator

I need to handle the client-side of a FIX implementation.
From the basic setup what I noticed is: once the message is sent the Initiator/client gets terminated in Eclipse while the Acceptor keeps listening on the port. Should the Initiator also have to be running indefinitely?
The application we are trying to build has to send messages
(NewOrderSingle, OrderCancelRequest)
to the Acceptor also have to receive messages for
Order Cancel Confirm/Reject, Execution Report, Trade Reversals etc)
from the Acceptor. Can both communications be done through a single Initiator in an asynchronous mode?
I.e. I need to handle both Inbound and Outbound messages in the client-side application. So if the client is not up how will the messages will be received at Initiator side?
Also in this case how will the Heartbeat messages keep happening since the Initiator is done? Do I need to run the Initiator in an infinite loop like
while {true}
I am a beginner in java/networking coding and in QuickFIX/J, so pardon if these are very basic questions.
Should the initiator be running indefinitely? Yes
Is initiator dual channel async comms? Yes
If the client is not up and messages are missed? Then QF defaults to the gap fill functionality.
If the client disco what happens to heartbeats? The reconnection logic kicks in.
Do I run the initiator in an infinite loop? No, the application starts its own thread. You just have to handle the 5 overrides and, if you are message cracking, handle each message type you need to.

how to check if queues of the RabbitMQ server is alive

I am totally new to spring framework. I am trying to create a java maven project where I can have the connectivity to the rabbitMq and I even before publish the message, I want to check if the queues are alive or not. Is this possible to ping the queue to see if it a alive or not.. I am totally new to this rabbitMQ.
Thanks for the answers
Checking for the availability of a queue is a bit of an anti-pattern with messaging systems.
The message producer should not care if there is something on the other end to receive / process the message. The producer only cares that the RabbitMQ instance is available, with the correct exchange.
If the message must be delivered to a consumer, guaranteed, then the consumer needs to configure the queue with durability in mind and the producer should send the message with the persistence flag to ensure it is written to disk.
...
re-reading your question, i'm wondering if you mean "rabbitmq server" when you say "queue". are you wanting to check if the rabbitmq server is available?
if that is the case, the proper thing to do is use a heartbeat in your RabbitMQ connection. the spring framework should know how to do this, and should respond with some kind of event or other code that executes when the connection dies. i'm not really familiar with spring, though, so i don't know the details of doing that with this framework.
You might check this post or this RabbitMQ page on handling this.

EJB client does not receive answer

I have JBoss 5 with ejb3 beans deployed to it.
If bean method execution takes a very long time (I checked that for 2 hours), then the client does not receive the answer when the EJB method execution finishes (with exception or not).
The client is blocked waiting for response from socket.
Why does that happen?
Most likely this is caused by a (stateful) router, packet filter, load balancer, SSL box whatever in between: They just terminate the connection after a certain time of inactivity, and the real endpoints are not notified. Experience shows that it's normally out of your control to have suitable timeouts in each device.
Anyway in your case, instead of curing the symptoms: A running request needs an open TCP connection, and possibly blocks a thread. So consider changing the design of your system from synchronous to asynchronous:
Use polling here, every minute should be enough. So you have a function to submit a task, and another one which returns "not yet ready" or "here is the result".
Use JMS queues in your client to submit tasks and to receive results

Notifying JMS Message sender (Web App) after message processed by Listener

I have a Web application (Flex 4 - Spring Blaze DS - Spring 3.0) which sends out an JMS event to a batch application (Standalone java)
I am using JMS infrastrucure provided by Spring (spring JmsTemplate,SimpleMessageListenerContainer,MessageListenerAdapter) with TIBCO EMS.
Is there any way by which we can notify a web user once message processing is completed by listener.
One of the way to send a response event which will be listened by web application; but
how to address following scenario:
User1 click on submit -> which in turn sends a JMS message
Listener on receiving message processes the message (message processing may take 20-30 mins to complete).
Listener application sends out another JMS event "Process_complete"
As this is a web application; there are n users currently logged into the application. so how to identify a correct user / what if user is already logged off?
Is there any way to handle this?
Please post your views.
In JMS i would use the ReplyTo Functionality together with temporary queues. When creating the Message you do also create a temporary Queue (with the createTemporaryQueue method of the Session) and set the JMSReplyTo Header to it. After that create a Consumer on the temporary Queue and start receiving. Maybe you want to give a timeout on the receive Operation and delete the temporary Queue after that timeout.
Some more thoughts on this can be found here: http://blog.temposwc.com/2010/03/asynchronous-jms-requestreply_25.html
I know only one way: create special notification queue and listen to this queue in your web application. When your listener implemented in stand alone application finished processing message it should send notification message to the notification queue.

JMS catching when a JMS server goes away

When there is a network problem which results in the client being disconnected from the JMS server, is there some other way to detect the problem other than waiting until the next JMS message being sent fails?
You can register an ExceptionListner with the JMS Connection using Connection.setExceptionListener(ExceptionListener)
The ExceptionListener will get notified of more problems than an actual disconnection, so you may have to filter the JMSException that gets passed to the listener.
ExceptionListener isn't necessarily enough. You also need to catch exceptions on any JMS calls you make (sending messages, for example). See Reconnecting JMS listener to JBossMQ
if your are running on MQ and looking to solve this problem, install a local MQ instance. More license but you will get guaranty delivery if your main corporate MQ goes down.
Other Option, use Spring and let the framework do the recovery of the connection.

Categories