Using Ja.NET


Chapter 4 shows how Ja.NET lets you to define .NET Framework proxy classes for Java classes, to enable .NET Framework applications to access Java classes. In a similar way, you can define .NET Framework proxy classes for the Java JMS classes to enable .NET Framework applications to make JMS message calls. This solution is somewhat different to those discussed so far, because the .NET Framework application is communicating through Java rather than interacting directly with the message queues. This implementation requires that you run a J2EE application server to provide .NET Framework with JMS access.

At first sight, this looks the same as the JNBridgePro solution; however, Ja.NET comes supplied with a ready-built JMS proxy. This is because all JMS invocations are implemented through interfaces. Hence you do not need to create a proxy yourself when you use Ja.NET.

Figure 9.5 shows the role of Ja.NET in asynchronous communications.

click to expand
Figure 9.5: The role of Ja.NET in asynchronous communications

Again, you need to configure message queues and decide on a data format.

Configuring the Message Queues

Because Ja.NET provides a wrapper for JMS, there is no special configuration required. However, you still need to configure WebSphere MQ for JMS support.

Deciding on a Data format for Ja.NET

Because Ja.NET wraps the JMS functionality, you can place a Java object directly into the message queue. The only task from a data perspective is to create a .NET Framework proxy of the Java data object, populate this with the data from .NET Framework, and then use this object to write the message.

Creating the Message Consumer for Ja.NET

Because the Ja.NET adapter places a JMS message in WebSphere MQ, you can use standard JMS code for reading the message. The message is in JMS format with a Ja.NET wrapper, so there is no need to change the data. Thus you can send it directly to the resource application. The following code sample shows how to read the message from JMS.

 InitialContext ic = new InitialContext(); QueueConnectionFactory factory = (QueueConnectionFactory) ic.lookup(connectionName); QueueConnection connection = factory.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = (Queue) ic.lookup(queueName); QueueReceiver receiver = session.createReceiver(queue); connection.start(); ObjectMessage message = (ObjectMessage) receiver.receive(); order = (OrderData) message.getObject(); DalServiceFacade facade = getFacadeHome().create(); return facade.saveOrder(order); 

The next section looks at creating the asynchronous interoperability adapter.

Creating the Ja.NET Asynchronous Interoperability Adapter

To create this adapter, use the prepackaged JMS proxy that ships with Ja.NET 1.5. This proxy is strong named so you can use it from within a COM+ context without problems. You also have to create proxy classes for any Java data types you want to access from .NET Framework. Remember to package the data into the Java classes before placing the message in the queue.

Note

Chapter 7 contains details for generating proxies for Ja.NET.

The following code sample shows how to send a message from .NET Framework to a JMS queue using Ja.NET.

 JNDIContext context = new JNDIContext(); object o = context.Lookup("javax.jms.QueueConnectionFactory", "XBikesQCF"); javax.jms.QueueConnectionFactory factory =     (javax.jms.QueueConnectionFactory) o; QueueConnection connection = factory.createQueueConnection(); QueueSession session =     connection.createQueueSession(false, SessionConstants.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = (javax.jms.Queue) context.Lookup("javax.jms.Queue", "XBikesQ"); QueueSender qSender = session.createSender(queue); qSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT); qSender.setPriority(4); qSender.setTimeToLive(0); connection.start(); ObjectMessage message = (ObjectMessage)session.createObjectMessage(); message.setObject(ejbOrder); qSender.send(message); 

Again, this is almost identical to sending a JMS message from Java, but the language is C#.




Application Interoperability. Microsoft. NET and J2EE
Application Interoperability: Microsoft .NET and J2EE: Microsoft(r) .Net and J2ee (Patterns & Practices)
ISBN: 073561847X
EAN: 2147483647
Year: 2003
Pages: 104

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net