JMS Example

Embed Size (px)

Citation preview

  • 8/3/2019 JMS Example

    1/3

  • 8/3/2019 JMS Example

    2/3

    package jmsclient;

    import java.util.Hashtable;

    import javax.naming.*;

    import javax.jms.*;

    public class SimpleJMSClient {

    private static InitialContext ctx = null;

    private static QueueConnectionFactory qcf = null;

    private static QueueConnection qc = null;

    private static QueueSession qsess = null;

    private static Queue q = null;

    private static QueueSender qsndr = null;

    private static TextMessage message = null;

    private static final String DEFAULT_QCF_NAME = "jms/MarksConnectionFactory";

    private static final String DEFAULT_QUEUE_NAME = "jms/MarksQueue";

    private static final String DEFAULT_URL = "t3://localhost:7101";

    private static final String DEFAULT_USER = "weblogic";

    private static 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());

    Page 2 of 3An updated simple WebLogic JMS client | RedStack

    9/14/2011http://redstack.wordpress.com/2010/02/17/an-updated-simple-weblogic- ms-client/

  • 8/3/2019 JMS Example

    3/3

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

    Share this: Share

    Like this: Be the first to like this post.Like

    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 FusionMiddleware, 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

    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

    tyskjohansays:

    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

    eblogic.jdbc.rmi.internal.ConnectionImpl_weblogic_jdbc_wrapper_JTAConnection_weblogic_jdbc_wrapper_XAConnection_oracle_jdbc_driver_Logic

    (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 Nelsonsays:

    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 rightJAR 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

    Page 3 of 3An updated simple WebLogic JMS client | RedStack

    9/14/2011http://redstack wordpress com/2010/02/17/an-updated-simple-weblogic- ms-client/