C # ACtiveMQ-to-peer data

Source: Internet
Author: User

1. Download ACTIVEMQ

Official website: http://activemq.apache.org/

2. Running ACTIVEMQ

Unzip Apache-activemq-5.10.0-bin.zip, and then double-click Apache-activemq-5.10.0\bin\win32\activemq.bat to run the ACTIVEMQ program.

After starting ACTIVEMQ, you can use the browser login: http://localhost:8161/admin/authentication, the default username is: admin password is: admin

(If you configure a good JDK environment, you can open the console for MQ to run successfully)

Download. NET version Dll:apache.nms-1.6.0-bin.zip and apache.nms.activemq-1.6.4-bin.zip at the same time

Download from here: http://archive.apache.org/dist/activemq/apache-nms/1.6.0/

    1. Referencing the Activemq class library:

(1) Apache.NMS.dll Path: \apache.nms.activemq-1.7.2-bin\lib\apache.nms\net-3.5

(2) Apache.NMS.ActiveMQ.dll path: \apache.nms.activemq-1.7.2-bin\build\net-3.5\debug

3.MQ Example (producer)      public Form1 ()         {            Initia Lizecomponent ();            Initproducer ();       }      Private iconnectionfactory factory;     public void Initproducer ()         {  &nbs P         try            {               //Initial chemical plant                 factory = new ConnectionFactory ("tcp://localhost:61 616 ");           }            catch      &NBSP ;     {                Lbmessage.text = "Initialization Failed";      &NBSP ;    }       }    private void Button1_Click (object sender, EventArgs e)   &NB Sp    {           //Establish factory connection             using (iconnection connection = Factory. CreateConnection ())             {               /through Factory connections Create session sessions                 using (isession session = connection. CreateSession ())                 {                   //Create a producer through a session, new in method queue                    the IMe Ssageproducer prod = session. Createproducer (New Apache.NMS.ActiveMQ.Commands.ActiveMQQueue ("Firstqueue"));                   //Create an object to send a message                     ITEX Tmessage message = Prod. Createtextmessage ();                    XmlDocument Doc= new XmlDocument ();                    Doc.loadxml ("<?xml version= ' 1 .0 ' encoding= ' UTF-8 '?><flightroute><flight><flightinfo><acid>cca1501</acid> <runway>13l</runway><gate>n115</gate><cockpitdirection>180</cockpitdirection ><deparr>DEP</deparr></flightinfo></flight</flightroute> ");                    message. Text = Doc.innerxml; Assign the actual message to this message object                    //Set the properties of the Message object, which is the filter condition of the queue and the only specified property of the peer                     message. Properties.setstring ("Filter", "Demo");                    Prod. Send (Message, Msgdeliverymode.nonpersistent, Msgpriority.normal, Timespan.minvalue);                    LBMESSAGE.text = "Sent successfully!" ";                    Text.text =" ";                    Text.focus ();               }    &NB Sp      }       }  

You can click the button to send something

Receive-side code (consumer)
 public Form2 ()         {            InitializeComponent ();  &N Bsp         Initconsumer ();       }        public void initconsum ER ()         {           //Create connection factory           &NBS P Iconnectionfactory factory = new ConnectionFactory ("tcp://localhost:61616");           // Create a connection through the factory             iconnection connection = factory. CreateConnection ();           //Connect server-side logo             CONNECTI On. ClientId = "Firstqueuelistener";             //Start connection             connection. Start ();           /Connect Create dialog             ISession session = C Onnection. CreateSession ();  &NBSp        //Create a consumer             Imessageconsumer consumer = Session through sessions. Createconsumer (New Apache.NMS.ActiveMQ.Commands.ActiveMQQueue ("Firstqueue"), "filter = ' demo '");           //Register for monitoring events             consumer. Listener + = new MessageListener (consumer_listener);       }        void Consumer_ Listener (IMessage message)         {            itextmessage msg = (IText Message) message;            Receivemessage.invoke (new Delegaterevmessage (Revmessage), msg);       }        public delegate void Delegaterevmessage (Itextmessage message );         public void Revmessage (Itextmessage message)         {            Receivemessage.text + = string. Format (@ "Received: {0}{1} ", message. Text, Environment.NewLine);       }        

Sent messages are present in the queue if they are not received.

C # ACtiveMQ-to-peer data

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.