In this topic I will be sharing the code to send ProtoBuf events from a standalone Java client to Universal Messaging Channel which is also a publishable document on the webMethods Integration Server using the UM Native Java API.
By having this capability Companies can use existing products to achieve a seamless integration between J2EE applications and webMethods without spending additional time and money on investing in new tools and infrastructure.
Also attached to this post is a detailed PDF documentation on how to implement the overall solution step by step.
Creating a publishable document with encoding type set to "Protocol buffers" will create a proto file on the file system where the publishable doc is stored. The contents of the publishable doc that i used for this use case looks like below.
Note:
If you want to skip over this blog and look at the step by step instructions on how to implement this then you can download the
PDF Documentation for this implementation. For any questions or if you are a client looking to request a demo feel free to reach out to aarremreddy@silverspringtech.com
Please note that this exercise is to demo the ability of publishing events to UM and does not include async error listeners or any other complex error handling scenarios.
Proto File content:
As part of pre-requisites install Google Protocol buffers compiler. Refer to the PDF documentation for more information. After this installation, run below command to generate the descriptor file for the proto file.
The variables nSession and nSessionAttributes are initialized as static since they are common properties that will be shared by the class objects.
The first step is to connect to the UM realm. In this case, I have a local instance of UM that does not have basic auth or SSL enabled so i am just using the realm endpoint for connection.
nsa = new nSessionAttributes("nsp://localhost:9000"); //This will be the realm endpoint that we are connecting to on the default 9000 port.
System.out.println("Session Attributes created.");
Once the connection is established then we have to create the Protbuf event.
Create a builder of instance com.google.protobuf.DescriptorProtos.FileDescriptorSet and load the descriptor file contents in to the builder. This is the first step to build the Protobuf event.
Create a filedescritor of instance com.google.protobuf.Descriptors.FileDescriptor from the builder that was generated above that holds the descriptor structure.
Create a descriptor of instance com.google.protobuf.Descriptors.Descriptor to get the message for "test_Akshith_docs_testPubDoc" in the descriptor file.
Create a builder for above descriptor and set the value for the field that needs to be published.
Repeat the same process as above to create a descriptor for envelope IData document since this is a mandatory field to populate by webMethods when publishing documents. See troubleshooting section in the pdf for more information. At least populate one field under envelope since it is mandatory.
Create a builder for sending the message to UM and set the values
Create a dynamic message of instance com.google.protobuf.DynamicMessage with the UM Message builder that was created above to generate the final event of instance com.pcbsys.nirvana.client.nProtobufEvent that can be sent to UM.
Set the channel name to send the message to. The exact channel name can be found on the webMethods publishable doc type property "Provider definition". Use this to set the channel name on Channel Attributes.
Create an nChannel instance by running findChannel method. This will set the channel object to the one referenced in above code.
At this point we have the protobuf event created from the descriptor file and the destination channel set. The event at this point needs to be published.
Standard catch block to handle any errors that happen while establishing a connection,creating a protobuf event or while finding the destnation channel.
Standard finally block to close the session to UM realm.
Troubleshooting\Error scenarios:
Issue:
If the publishable doc type is not changed from default IData Encoding type to "Protocol buffers" then the standalone Java app will not error but on the consumer end, below error will be logged in the wM IS server log and message will not be processed.
ERROR:
2024-11-05 13:15:57 EST [ISS.0153.0089C] (tid=165624) Trigger test.Akshith.triggers:receiveJavaMessages failed because of message decoding exception: com.wm.app.b2b.server.dispatcher.exceptions.MessagingCoderException: [ISS.0153.9302] Protocol buffer coder cannot find descriptor in document type: test.Akshith.docs:testPubDoc. Message has been acknowledged to messaging provider.
Issue:
If there are issues connecting to the realm then below error will happpen. Check you realm connection details and try again.
Error : com.pcbsys.nirvana.client.nRealmUnreachableException: Realm is currently not reachable:Realm was still unreachable after max retry count - 0
Issue:
If you do not populate the envelope descriptor while sending the event to channel then it will not error out in Java app but on the consumer side you will notice below error in wM Integration Server.
Error :
2024-11-05 10:20:18 EST [ISS.0153.0041E] (tid=330770) webMethods Messaging Trigger test.Akshith.triggers:receiveJavaMessages failed preprocessing: java.lang.NullPointerException: Cannot invoke "com.wm.data.IData.getCursor()" because "env" is null
Issue:
If you do not populate the correct datatype while setting the values for fields then below error will occur in the Java app and it will go in to catch block. You can refer to the proto filet to get the correct data type for each field.
Error :
java.lang.IllegalArgumentException: Wrong object type used with protocol message reflection.Field number: 33, field java type: LONG, value type: java.lang.String
Issue:
If the correct channel name is not provided then below error will occur. Check the "Provider definition" property on the publishable doc type on webMethods Integration server.
Error :com.pcbsys.nirvana.client.nChannelNotFoundException: Channel could not be found on the server:Find : /wmtest/is/test/Akshith/docs/testPubDoc