Access a Java Message Service Topic from .NET Using J-Integra® for .NET |
This example demonstrates how to access a Java Message Service Topic from .NET client. J-Integra® for .NET is a Java interoperability component that bridges Java/J2EE and Microsoft .NET. It provides bi-directional access of Java objects and .NET components.
Use this example as a guideline to show you how to access a Java Message Service (JMS) topic from .NET using J-Integra for .NET. This example illustrates a very simple multi-client chat program. Each .NET client will connect to a JMS topic and add itself as a listener. An event occurs when a message is typed by one of the .NET clients. Each message is then sent to every listening .NET client. This example will access a JMS topic on BEA's Weblogic 8.1 Application Server.
The Steps to Follow will show you how to deploy J-Integra® for .NET correctly for this example.
A platform with Microsoft Visual Studio .NET 2003 (7.1.3088 or higher) installed, or at least the .NET Framework 1.0.3705 or higher. This will be known throughout the example as the .NET platform.
A platform with Weblogic 8.1 and J-Integra for .NET 1.5.1265 (or higher) installed. This will be known throughout the example as the Java platform.
A version of JDK (1.3.1 or higher) installed on the Java platform, and the bin directory included in the path. This required to run the Java server.
Verify that GenService is installed correctly on the .NET platform.
Perform this step on the Java platform.
In this step, you will need to configure J-Integra for .NET as a server so it can respond to incoming TCP requests. This is done through the Janetor tool.
Launch Janetor from the Start Menu.
java -jar $USER_INSTALL_DIR$\lib\janetor.jar
Go to File - Open and open janet.xml located in $USER_INSTALL_DIR$\JMS\java_server.
Install your J-Integra for .NET product license. See Installing the J-Integra® for .NET license for further information.
Select default under Local Objects. Here you see that J-Integra for .NET exposes all Java classes as Client Activated Objects (CAO's) at the given machine address and port using TCP.
Select default under Remote Objects. Here you see that J-Integra for .NET is configured to access a CAO using TCP. Notice that URI is blank - this is because there is no one specific endpoint for J-Integra for .NET to call the .NET client's event handler. This is fine, since the client will pass over the correct URI when it first accesses the J-Integra® for .NET server.
Before you exit Janetor, save the configuration by going to File - Save.
Perform this step on the Java platform.
In this step, you will start Weblogic 8.1 and the J-Integra for .NET server.
Start the Weblogic 8.1 Examples Server by executing the startExamplesServer script located in BEA_HOME\weblogic81\samples\domains\examples.
At the command-line, set up the Weblogic 8.1 environment by executing the setExamplesEnv script located in BEA_HOME\weblogic81\samples\domains\examples.
In the same command-line, add $USER_INSTALL_DIR$\lib\janet.jar to the CLASSPATH (note: add, do not overwrite), change directory to $USER_INSTALL_DIR$\examples\JMS\java_server and enter:
java com.intrinsyc.janet.Main
Perform this step on the Java platform.
In this step, you will use the GenNet tool to generate .NET proxies for the Java classes.
Launch GenNet from the Start Menu.
Change directory to $USER_INSTALL_DIR$ and then enter:
java -jar lib\gennet.jar
The first screen of GenNet shows a list of machines that have GenService running (screenshot not shown). Select the appropriate one and click Next.
The next screen prompts for the components (JAR files or directories)
to be added to the CLASSPATH. Each of these components are required
in order for the Java runtime to resolve references to Java classes when
generating .NET proxies. You'll need to add the following component:
- BEA_HOME\weblogic81\lib\weblogic.jar
Move on to the next step by clicking Next.
The next screen prompts for the specific Java classes that will
have .NET proxies generated for them. Click on Browse...
to add the following classes (use the CTRL key to select
multiple classes):
- com.intrinsyc.janet.JNDIContext
- javax.jms.TopicConnectionFactory
- javax.jms.Topic
- javax.jms.TopicPublisher
- javax.jms.TopicSession
- javax.jms.Message
- javax.jms.TopicSubscriber
- javax.jms.TopicConnection
- javax.jms.MessageListener
- javax.jms.TextMessage
Click on the Filter button and choose not to generate any proxies for the referenced classes as shown below. This will eliminate the number of .NET proxies created.
Move on to the next step by clicking Next.
The next screen prompts you to specify the .NET Assembly name along with the output directory. The screen shot may show a different output directory than the Output Directory value shown here, but it should be pointing to $USER_INSTALL_DIR$\examples\JMS\csharp_client\bin\Debug.
You should see a message that the proxy generation was successful. Click Exit to exit GenNet.
Perform this step on the .NET platform.
In this final step, you will configure the .NET client(s) using a configuration file, then compile and run it.
Modify remoting_tcp.config in $USER_INSTALL_DIR$\examples\JMS\csharp_client\bin\Debug to look like:
<configuration> <system.runtime.remoting> <application> <client url="tcp://localhost:9099"> <activated type="com.intrinsyc.janet.JNDIContext, JanetExample"/> </client> |
Notice that tcp://localhost:9099 matches what was entered under Local Objects in Janetor. Change accordingly if necessary.
Perform the following step twice to launch two different chat clients: change directory to $USER_INSTALL_DIR$\examples\JMS\csharp_client\bin\Debug and launch csharp_client.exe.
At this point, you should see two different chat clients. Enter a different name for each client, then type a message in one of the clients and you will see that all clients receive it:
© 2007 Intrinsyc Software International, Inc. All rights reserved. Legal |