Create Solace Output Adapter Spring
Solace Output Adapter Introduction
A custom built output adapter called Solace Output adapter will be developed in Java using Spring framework that can be used to publish messages on Solace compliant messaging bus. It can be embedded to any java based project to send message in JMS Text Message formats.
Connection to Solace Messaging server
By default adapter will be configured to connect Solace Messaging server one time only before throwing an exception, if it fails to connect messaging server, will throw an exception called “com.solacesystems.jcsmp.JCSMPErrorResponseException”. Client can configure this default property to retry connection to certain number of times at set interval before throwing exception. To do this, client can set SERVER_NUM_RETRIES and SERVER_RECONNECT_INTERVAL in seconds attributes in properties file. The server-num-retries attribute controls the number of times the adapter will try to connect before throwing an exception. The default value will be set to 0 which specified no retry will be attempted; maximum value is MAX_INT. The SERVER_RECONNECT_INTERVAL in seconds attribute will control time duration between next connection attempts will be made. The default value to this attribute will be 30 seconds.
Destination routing of Solace messaging is configurable through routing section in the properties file with below attributes:
All fields are required. If any of the fields are missing the adapter will throw an exception “com.solacesystems.jcsmp.JCSMPErrorResponseException” with a detail message. If more than one queue names needs to be specifies then this should be separated with a comma. It’s also possible to specify multiple servers for clustered environment; they should also separate by comma.
Solace Message Translation
This adapter will accept message only as a String format. It will convert the String to JMS Text Message then publish the message to the Solace bus.
Solace output writer and Delivery Mode
Adapter will create Solace message to JMS Text Message type and deliver them to the Solace Messaging bus. Solace message can be delivered with either of two delivery mode: DeliveryMode.PERSISTENT or DeliveryMode.NON_PERSISTENT and by default DeliveryMode.PERSISTENT will be set by the adapter and it can be change to DeliveryMode.NON_PERSISTENT in configuration properties file with attribute name: DeliveryMode. This could be finding in delivery mode section in the properties file.
Type checking and Error Handling
Solace output adapter will perform two checks during process start. It will ensure that a value for its configuration which is required and mentioned in the document has been specified. Default configuration will be set for the field which is not required. If any of the required filed has not been set, “com.solacesystems.jcsmp.JCSMPErrorResponseException” will be thrown with proper message.
Solace adapter logging
By default logging is enabled and it’s configurable through Solace.properties file. If user disables logging then it will only disable logging for info and debug. Note: All logging error level will be enabled and it’s not configurable.
Now let’s dive into its implementation using Spring framework. Below are needed:
- Eclipse 4.0 or up
- JDK 1.8
- Maven 3.2
- Solace version 126.96.36.199
Note: Its assumed that you have access to Solace server and Output queue has been created.
- Create maven project name: SolaceOutputAdapter belwo is final project structure:
- Please add below dependency in your pom.xml:
- SolaceOutputAdapter.java: Main output adapter class which connect to Solace and provide all supported method to send message to Solace messaging bus:
- SolacePublisher.java: An interface which will be exposed to the client to send message to Solace messaging server:
- SolacePublisherImpl.java: This is real class which implements SolacePublisher and send message to Solace messaging server:
- Now its time to run our application. Please use class SolaceApplicationTest.java which will load Spring context and send message to Solace server:
- Download source code: SolaceOutputAdapter