[go: up one dir, main page]

0% found this document useful (0 votes)
134 views3 pages

JMS Example

The document presents an updated Java code for a simple JMS client that can send messages to a WebLogic JMS queue. The code includes classes to create an InitialContext, QueueConnectionFactory, QueueConnection, QueueSession, Queue, and QueueSender to send a TextMessage to the queue. The code also shows how to pass in configuration details like the server URL, queue name, etc. to make the client more reusable. Future posts are planned to demonstrate using this client to integrate Oracle UCM with JMS and also presenting the client code in C#.

Uploaded by

Komal Kandi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views3 pages

JMS Example

The document presents an updated Java code for a simple JMS client that can send messages to a WebLogic JMS queue. The code includes classes to create an InitialContext, QueueConnectionFactory, QueueConnection, QueueSession, Queue, and QueueSender to send a TextMessage to the queue. The code also shows how to pass in configuration details like the server URL, queue name, etc. to make the client more reusable. Future posts are planned to demonstrate using this client to integrate Oracle UCM with JMS and also presenting the client code in C#.

Uploaded by

Komal Kandi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

An updated simple WebLogic JMS client | RedStack

Page 1 of 3

RedStack
Musings on Integration with Oracle Fusion Middleware

An updated simple WebLogic JMS client


Posted on February 17, 2010 by Mark Nelson

A little while ago, we posted a simple JMS client for WebLogic here. That post demonstrated how to create a simple JMS client program that could send messages to a WebLogic JMS queue. It also showed how to set up the necessary definitions on the WebLogic Server in the first place, and how to see the details of the messages after they had been sent. In that post we mentioned that there are often times when we want to be able to send messages to a JMS queue. One such time was recently when we wanted Oracle Universal Content Management (UCM) to send a JMS message every time a new piece of content was checked in to the content management system. In order to do that, we reused this code, but it needed a small update to allow us to pass in details of the server, queue name, etc. This post presents an updated simple JMS client, in Java. Here it is still general purpose. In a future post, we will show how it is used to satisfy the use case described above. We will also present this updated simple client in C# in a separate post. This post will be updated with links when these new posts are published. Update: You can grab this code from our Subversion repository: svn checkout https://www.samplecode.oracle.com/svn/jmsclients/trunk The C# version is here and a Scala version here. Please refer to the earlier post for details of how to use this code.
RedStack
Theme: Twenty Ten Blog at WordPress.com .

http://redstack.wordpress.com/2010/02/17/an-updated-simple-weblogic-jms-client/

9/14/2011

An updated simple WebLogic JMS client | RedStack

Page 2 of 3

package jmsclient; import java.util.Hashtable; import javax.naming.*; import javax.jms.*; public class SimpleJMSClient { private private private private private private private private private private private private static static static static static static static static static static static static InitialContext ctx = null; QueueConnectionFactory qcf = null; QueueConnection qc = null; QueueSession qsess = null; Queue q = null; QueueSender qsndr = null; TextMessage message = null; final String DEFAULT_QCF_NAME = "jms/MarksConnectionFactory"; final String DEFAULT_QUEUE_NAME = "jms/MarksQueue"; final String DEFAULT_URL = "t3://localhost:7101"; final String DEFAULT_USER = "weblogic"; final String DEFAULT_PASSWORD = "weblogic1";

public SimpleJMSClient() { super(); } public static void sendMessage(String messageText) { sendMessage(DEFAULT_URL, DEFAULT_USER, DEFAULT_PASSWORD, DEFAULT_QCF_NAME, DEFAULT_QUEUE_NAME, messageText); } public static void sendMessage(String url, String user, String password, String cf, String queue, String messageText) { // create InitialContext Hashtable properties = new Hashtable(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password); try { ctx = new InitialContext(properties); } catch (NamingException ne) { ne.printStackTrace(System.err); System.exit(0); } System.out.println("Got InitialContext " + ctx.toString()); // create QueueConnectionFactory try { qcf = (QueueConnectionFactory)ctx.lookup(cf); } catch (NamingException ne) { ne.printStackTrace(System.err); System.exit(0); } System.out.println("Got QueueConnectionFactory " + qcf.toString()); // create QueueConnection try { qc = qcf.createQueueConnection(); } catch (JMSException jmse) { jmse.printStackTrace(System.err); System.exit(0); } System.out.println("Got QueueConnection " + qc.toString());

http://redstack.wordpress.com/2010/02/17/an-updated-simple-weblogic-jms-client/

9/14/2011

An updated simple WebLogic JMS client | RedStack

Page 3 of 3

Share this: Like this:

Share Like Be the first to like this post.

About Mark Nelson Mark Nelson is a Consulting Solution Architect in the Fusion Middleware Architects Team (known as The A-Team) in Oracle Development. Their mission is to supply deep technical expertise to support customers deploying Oracle Fusion Middleware, and to collect real world feedback to continuously improve the product set. Before joining Oracle Development in 2010, Mark worked in Sales Consulting at Oracle since 2006 and various roles at IBM since 1994, including several in Software Group and System/390 Group across Asia Pacific. View all posts by Mark Nelson

This entry was posted in Uncategorized and tagged JMS, WebLogic. Bookmark the permalink.

5 Responses to An updated simple WebLogic JMS client


Pingback: A simple JMS client for WebLogic 11g RedStack

Pingback: An updated simple WebLogic JMS client in .Net (C#) RedStack

Pingback: Improving JMS Performance on WebLogic | RedStack

tyskjohan says:
March 7, 2011 at 6:57 pm

Hi I cant get this to work, I get an exception when calling the send(message)
Set text in TextMessage oracle.jms.AQjmsTextMessage@818e58b Exception in thread "Main Thread" weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception at

weblogic.jdbc.rmi.internal.ConnectionImpl_weblogic_jdbc_wrapper_JTAConnection_weblogic_jdbc_wrapper_XAConnection_oracle_jdbc_driver_LogicalConnection_1033 (Unknown Source) Caused by: java.rmi.MarshalException: error marshalling return; nested exception is: java.io.NotSerializableException: oracle.jdbc.driver.T4CConnection

What could cause this?


Log in to Reply

Mark Nelson says:


March 7, 2011 at 7:15 pm

Hi, Looks like you might be importing the wrong class there. AQ is the messaging provider in the Oracle Database. You want to make sure you are using the normal Java JMS classes. I would go back and check you have the right JAR files in your classpath for your application, and if you are using an IDE, make sure it did not import the wrong classes.
Log in to Reply

http://redstack.wordpress.com/2010/02/17/an-updated-simple-weblogic-jms-client/

9/14/2011

You might also like