WebSphere MQ programming instance --- JMS

Source: Internet
Author: User
Import Java. util. hashtable; import javax. JMS. *; import javax. naming. *; import javax. naming. directory. *; public class sample {protected queueconnectionfactory factory = NULL; protected queueconnection connection; protected queuesession; protected textmessage outmessage; protected queuesender; protected quit fail; public static final string qcflookup = "qcfc"; Publ IC static final string qlookup = "Q1"; public static final string ICF = "com. sun. JNDI. fscontext. reffscontextfactory "; Public String url =" file:/D:/testmq/CTX/"; Public void sampleinit () throws exception {hashtable environment = new hashtable (); environment. put (context. initial_context_factory, ICF); environment. put (context. provider_url, URL); environment. put (context. referral, "Throw"); Context CTX = N EW initialdircontext (Environment); factory = (queueconnectionfactory) CTX. lookup (qcflookup); queue Q1 = NULL; Q1 = (Queue) CTX. lookup (qlookup); connection = factory. createqueueconnection (); queuesession = connection. createqueuesession (false, session. auto_acknowledge); queuesender = queuesession. createsender (Q1); queuesender. setdeliverymode (deliverymode. non_persistent); outmessage = queuesession. createte Xtmessage (); queuereceiver = queuesession. createreceiver (Q1); connection. start ();} public void sendmessageout (string message) throws jmsexception {outmessage. settext (Message); queuesender. send (outmessage);} Public String receivemessage () throws exception {return (textmessage) queuereceiver. receive ()). gettext ();} public void sampleclose () throws jmsexception {queuesession. close (); connection. c Lose ();} public static void main (string [] ARGs) {string REC; sample sp = new sample (); try {sp. sampleinit (); SP. sendmessageout ("this is a test! "); Java. lang. thread. sleep (4000); Rec = sp. receivemessage (); system. out. println ("receive text is:" + REC); SP. sampleclose ();} catch (exception e) {e. printstacktrace ();}}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.