First, let's introduce MQ. The English name of MQ is MessageQueue, and the Chinese name is the message queue used by everyone. In other words, it is a container for receiving and forwarding messages, it can be used for message pushing.
The following topic describes ActiveMQ today:
He is an open-source Message Queue software developed by Apache. It runs in JVM and supports multiple languages, such as JAVA, C ++, and C #.
First, we will introduce how to configure the server side of ActiveMQ:
1. download the software.
Go to the official website download: http://activemq.apache.org/I download is the apache-activemq-5.8.0-bin 5.8 version, of course, the open source is also supported to download source, need to compile your own, here not too much Introduction
2. decompress the package and start activemq. bat in \ apache-activemq-5.8.0 \ bin \ win32. The system automatically executes the startup process. Of course, if the installation fails, the JVM environment is not installed.
3. Open the browser and enter http: // localhost: 8161/admin/. The default configuration is this. Of course, you can change this configuration.
4. Now, the server is started
--------------------------------- Perfect split -----------------------------------
Today is the topic. How to Use the API provided by ActiveMQ in C # to subscribe to and publish messages
1, first need to download the ActiveMQ provided by the API function, this also from the official website under Apache. NMS-1.6.0-bin and Apache. NMS. ActiveMQ-1.6.0-bin these two dll are in the downloaded folder after the bin directory;
2. Reference these two files in the project;
3. In ActiveMQ, there are two concepts: one is the Producer and the other is the Consumer. The Producer is the publisher we often call, and the Consumer is the subscriber, this may be a better explanation. If you do not know the publish/subscribe mode, you can understand the meaning literally. The publisher publishes messages, and the subscriber subscribes to events, receive the message;
4. Run the Code directly. Run the Winform code. If you do not want to handle the interface thread callback problem, you can use the Console program.
5. Produce
factory = ConnectionFactory( lbMessage.Text = btnConfirm_Click( (IConnection connection = (ISession session = IMessageProducer prod = session.CreateProducer( Apache.NMS.ActiveMQ.Commands.ActiveMQQueue( ITextMessage message = message.Text = message.Properties.SetString(, lbMessage.Text = txtMessage.Text = }
6. consumer
IConnectionFactory factory = ConnectionFactory( IConnection connection = connection.ClientId = ISession session = IMessageConsumer consumer = session.CreateConsumer( Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(), consumer.Listener += ITextMessage msg = tbReceiveMessage.Invoke( tbReceiveMessage.Text += .Format( }
7. Start the interface.
Today, I am talking about Buddhism. I also received a task to develop MQ in the afternoon. I hope that you will continue to study it, of course it's okay. Let's take a look at the API code and see how the above is implemented. The benefits of open-source are not much said. I did my homework.