How to capture com.solacesystems.jcsmp.JCSMPErrorResponseException: 503
Hello
I am using com.solacesystems.jms.SolConnection to create a connection to my cloud example.
When I disable the mssage VPN, I get the following error in the wrapper log:
TcpClientChannel 09Jun2020 20:43:36 Connection attempt failed to host 'xxxxxxx.messaging.solace.cloud' ReconnectException ((Client name: xxxxxx Local addr: xxxxxx Remote addr: xxxxxxx) - ) com.solacesystems.jcsmp.JCSMPErrorResponseException: 503: Message VPN Unavailable [Subcode:9]
How can I capture this within my java class? I've implemented SolConnectionEventListener, but that only gets me "CAUSE: com.solacesystems.jcsmp.JCSMPTransportException: Error receiving data from underlying connection."
Comments
-
Ok... so you're shutting down the VPN to simulate a network outage? That's cool. The API will automatically attempt to reconnect for the amount of times specified in your JCSMPChannelProperties. By default, only once all reconnect attempts have failed will a (transport) exception be thrown up to the application to signal there was a failure.
But if the application wants to be notified of disconnect/reconnect events (e.g. to set a GUI element or something), then you gotta implement the JCSMPReconnectEventHandler when you create the Consumer object: https://docs.solace.com/API-Developer-Online-Ref-Documentation/java/com/solacesystems/jcsmp/JCSMPSession.html#getMessageConsumer(com.solacesystems.jcsmp.JCSMPReconnectEventHandler, com.solacesystems.jcsmp.XMLMessageListener)
Hope that helps!
1 -
Ok... first off... I misread/misunderstood your original question... you were looking to find how to capture the more detailed log/reason information in your exception, correct? Not just have your application be aware of connection issues? If the former, I don't think you can get the exact reason in the exception.
Anyhow... if it was the latter... in JMS, the JMS specification doesn't explicitly provide any mechanism to "listen" to disconnect/reconnect events. Only once your connection retry attempts are exhausted does the API throw a JMSException up to the applicaiton. Usually.
But in Solace, there is a way for a JMS app to hook up to these notification events... check out: https://docs.solace.com/Solace-JMS-API/Managing-Sessions.htm#Handling
It is possible to register an SolConnectionEventListener to receive callbacks whenever the connection state transitions. Here is an sample snippet:
SolConnectionEventSource eventSource = (SolConnectionEventSource) jmsConnection; eventSource.setConnectionEventListener(new SolConnectionEventListener() { @Override public void onEvent(SolConnectionEvent event) { System.out.println(event.getType()); }});
Javadocs can be found at:
https://docs.solace.com/API-Developer-Online-Ref-Documentation/jms/index.html
You will need to search for SolConnectionEventListener.3