Activemq platform construction and C # display column,
ActiveMQ
ActiveMQ is the most popular and powerful open-source message bus produced by Apache. ActiveMQ is a JMS Provider that fully supports the JMS1.1 and J2EE 1.4 specifications. Although it has been a long time since the JMS specifications were introduced, however, JMS still plays a special role in today's J2EE applications.
Features
Environment preparation
I use Windows 7 as the column
Install
Decompress the downloaded installation package to any local disk.
Start activemq Service
The interface after successful startup is
If errors such as major. minor version51.0 occur, they are all caused by java version installation errors. You can solve the problem by installing Versions later than 1.6.
After successful startup, http: // localhost: 8161/admin, default user name and password admin/admin. If you want to change the user name and password, In the conf/jetty-realm.properties.
If you need to modify the port, you can modify it in the jetty file.
The administrator interface is as follows:
ActiviteMQ basic process for receiving and sending messages
From http://www.cnblogs.com/hoojo/p/active_mq_jms_apache_activeMQ.html
To send a message, follow these steps:
(1) create a connection using the factory type JMS ConnectionFactory
(2) Use the management object JMS ConnectionFactory to establish a Connection and start
(3) Use Connection to establish a Session
(4) use the Session and management object Destination to create the MessageSender for the message producer.
(5) use the message producer MessageSender to send messages
Procedure for a message recipient to receive a message from JMS
(1) create a connection using the factory type JMS ConnectionFactory
(2) Use the management object JMS ConnectionFactory to establish a Connection and start
(3) Use Connection to establish a Session
(4) use the Session and management object Destination to create the Message Receiver MessageReceiver
(5) When the Message Receiver MessageReceiver is used to receive the message, you need to use setMessageListener to bind the MessageListener interface to the MessageReceiver message receiver. The MessageListener interface must be implemented and the onMessage event method needs.
C # Message Queue writing
Download the latest Apache. NMS from ActiveMQ official website.
Http://www.apache.org/dyn/closer.lua/activemq/apache-nms/1.7.0/Apache.NMS.ActiveMQ-1.7.1-bin.zip
Create a C # project and add the two DLL files to the project.
The write address is as follows:
Write the account. The password is as follows:
The write code is as follows:
Namespace ConsoleApplication21 {class Program {static void Main (string [] args) {String QueuesNameESF = "queue: // test. log "; Uri _ uri = new Uri (String. concat ("activemq: tcp: // 10.58.8.239: 61616"); IConnectionFactory factory = new ConnectionFactory (_ uri); using (IConnection conn = factory. createConnection ("admin", "manager") {using (ISession session = conn. createSession () {IDestination destination = SessionUtil. getDestination (session, QueuesNameESF); using (IMessageProducer producer = session. createProducer (destination) {conn. start (); // It can be a string or an xml string or other ITextMessage request = session. createTextMessage ("messsage"); producer. send (request );}}}}}
After writing, you can view
The read code is as follows:
using System;using Apache.NMS;using Apache.NMS.ActiveMQ;using Apache.NMS.Util;namespace ConsoleApplication21{ class Program { static void Main(string[] args) { String QueuesNameESF = "queue://test.log"; Uri _uri = new Uri(String.Concat("activemq:tcp://10.58.8.239:61616?wireFormat.maxInactivityDuration=0")); IConnectionFactory factory = new ConnectionFactory(_uri); using (IConnection conn = factory.CreateConnection("admin", "manager")) { using (ISession session = conn.CreateSession()) { conn.Start(); IDestination destination = SessionUtil.GetDestination(session, QueuesNameESF); using (IMessageConsumer consumer = session.CreateConsumer(destination)) { ITextMessage message = consumer.Receive() as ITextMessage; Console.Write(message.Text); } } } Console.ReadLine(); } }}
Author: Sakya bitter monk Source: http://www.cnblogs.com/woxpp/p/5001373.html this article copyright belong to the author and blog park a total, welcome to reprint, but without the author's consent must retain this paragraph of the statement, and in the Article Page clearly given the original connection.