This is the first blog in a series about the JNBridge JMS Adapter for .NET. This adapter, like its sibling BizTalk adapter, surfaces the Java Message Service API, a standard Enterprise Java messaging interface. The Java/.NET interoperability technology in JNBridgePro allows either adapter to use any vendor’s Java JMS client JAR files. The .NET adapter uses the Windows Communication Foundation Line-Of-Business Adapter SDK to surface the JMS API with a custom WCF transport channel. This channel can generate WCF bindings that provide two patterns: request/response outbound and one-way receive inbound. Outbound operations provide a simple send/receive messaging interface. Inbound operations are asynchronous channel listeners, essentially a WCF service that listens for incoming messages, the .NET equivalent of an Enterprise Java message driven bean. The adapter can generate the WCF binding in C# or VB using a design-time tool used to select the outbound or inbound operations available from the adapter. At run-time, the resulting channel stack can be used by client code to send and receive messages while hiding the underlying JMS class hierarchy of connections, sessions, message producers and consumers.
In most cases, the resulting WCF binding is used in a single process. If it is an inbound channel, it can run in a WCF Service Host process or as a NT service. However, the JMS .NET adapter also supports Web Services, so it is possible to deploy the channel into IIS as an application. This series of blogs will explore using the adapter to create an outbound binding exposed as web services and inbound channels deployed as App Fabric services in IIS.
This first blog will explore exposing outbound operations using Web Services. One the service is deployed to IIS, a simple client can be generated that from the exposed WSDL enabling it to publish a JMS message with a custom header to a JMS queue.
For an introduction to the .NET JMS Adapter, please see this tutorial on building simple messaging clients.
Building this example requires the JNBridge JMS Adapter for .NET and Visual Studio version 2010,2012 or 2013. Deployment requires IIS 7.5, or later, and AppFabric for Windows Server. A JMS implementation would also be nice, this example uses Apache ActiveMQ.
Create the Outbound Binding
Using Visual Studio, create a new WCF Service Application project named WcfJmsOutboundSvc. Visual Studio will try and be helpful and create a default interface, implementation and service reference called Service1. Clean up the project and delete the files IService1.cs, Service1.svc.cs. Rename the file Service1.svc to JmsClient.svc. Also, be sure to target the service for .NET 4.5.1.
Now open the Add Adapter Service Reference dialog from Visual Studio’s Project menu. This dialog consumes any WCFLOB adapter allowing the developer to choose individual messaging operations. Here’s what the dialog looks like when completed.
Before choosing the operations, the first step is to select the appropriate WCF binding, JNBridgeDotNetJMSAdapter, and configure the adapter by clicking on the Configure button. The configuration for the adapter is shown in the two screen shots, below. Note that the chosen JMS implementation is ActiveMQ and that the property, Work Off Line, is set to true. Working offline means that when the Connect button is clicked, the adapter does not attempt to connect to the server, instead providing generic operations. As shown above, a single generic operation has been chosen, SendAnnotatedText(). This operation will publish a JMS Text message with a custom JMS header.
When the OK button is clicked on the Add Adapter Service Reference dialog, a WCF channel is generated from metadata supplied by the adapter. The generated channel code in the file, JMSAdapterBindingClient.cs, is shown below. The client channel includes the selected operation, SendAnnotatedText(), along with all dependent methods and definitions.
Configuring the WCF Service
When the proxy client is generated, the adapter also modifies the configuration file, Web.config, adding the adapter’s WCF configuration. In order to properly deploy the WCF proxy client to IIS, we’ll have to make some edits to that configuration file. In addition, the JmsClient.svc will also have to be edited.
Remember that Visual Studio thoughtfully created an example Web Service called Service1. The service definition file, Service1.svc, was renamed to JmsClient.svc. Now that file must be edited to point to the WCF proxy file, JMSAdapterBindingClient.cs. This is the edited service definition. Highlighted lines are those modified.
The modifications to Web.config mostly have to do with eliding the references to the example Service1, substituting the names in the generated WCF proxy. However, there are two important modifications. The first is changing the adapter binding property, OffLine, to false from true. More importantly, the default web services protocol for the <services><service><endpoint> binding must be changed to wsHttpBinding from basicHttpBinding. The modified lines are highlighted.
Publishing the Service to IIS
The WCF binding can be deployed to IIS or IIS Express. IIS is chosen here because the Express development version is only 32-bit. A 64-bit process provides the JVM more contiguous memory for its heap. Here is the publish configuration to a local IIS instance.
Once published to IIS, the service can be started by simply starting the default web site in IIS.
Creating a Client
Now that the service is up and running, a client stub can be generated. This client will be able to publish a JMS message with a custom header to the JMS queue. This client can run on any machine and doesn’t require the .NET JMS adapter, which resides on the IIS server. In this example, the client will be a simple console application. The client stub is generated by using the Add Service Reference dialog in Visual Studio. Here’s what the dialog looks like before clicking OK.
Once the client has been generated, it’s a simple matter to create a client, connect to the Web Service running in IIS, create a JMS Text message with a custom header attribute and publish that message to an ActiveMQ broker.
When the client is executed, a JMS message is published to the destination, dynamicQueues/exampleQueue. Here’s the Administration Console for ActiveMQ displaying the message sent by the client.
In conclusion, this blog demonstrates using the JNBridge JMS Adapter for .NET to create a WCF channel that can be deployed to IIS as a Web Service. The outbound operation, essentially a SOAP request/response, allows a WS client to publish a JMS message to a queue. The next installment of this blog will concentrate on an inbound service channel to consume the messages published by this client.