NET use of Activemq author and Source: The Mystery of multithreading-blog Park collection to →_→: Summary:. NET use of Activemq". NET use of ACTIVEMQ ":
Key Words:NET under ACTIVEMQ use
Just came to a new company, because the project needs, to use ACTIVEMQ, so the study, write down this note, learn from the Macaidong blog and CSDN related information
ACTIVEMQ IntroductionACTIVEMQ is an open source, based on the apache2.0 licenced, realize the jms1.1 of the message middleware at first do not know what is called middleware, and then study the concept of middleware, if you do not understand the can see, will be directly skipped.
Middleware (middleware) is an independent system software or service program, it is on the operating system, network and database, the application of the lower layer of software, the overall role is to be in their upper layer of application software to provide a running and development environment, to help users flexible, Develop and integrate complex application software efficiently.
The role of middleware: Specifically, the middleware shielding the complexity of the underlying operating system, so that programmers face a simple and unified development environment, reduce the complexity of programming, focus on their own business, There is no need to repeat the process of porting the program to different system software, which greatly reduces the technical burden. Middleware brought to the application system, not only the development of the simple, development cycle of shortening, but also reduce the system maintenance, operation and management of the workload, but also reduce the total cost of computer input.
Classification of middleware:
Middleware covers a wide range of applications to different needs to emerge a variety of unique middleware products. However, there is not a more precise definition of middleware so far, so the classification of middleware will be different at various angles or different levels. Since middleware needs to shield heterogeneous operating systems and network protocols in distributed environments, it must be able to provide communication services in a distributed environment, which we call the platform. Depending on the purpose and the implementation mechanism, we divide the platform into the following major categories:
Remote Procedure calls (remotely procedure call) RPC
Message-oriented middleware (message-oriented middleware) Mom
Object Request Agent (brokers) OrbEnter the following topic: firsthttp://activemq.apache.org/download.html Download the latest version of MQ
ACTIVEMQ use under. NET:
1.
Add a reference to Apache.nms.dll and Apache.nms.activemq.dll
2. Writing producer producer Code
1ClassProgram2{3Staticvoid Main (String[] args)4{5Try6{7//Create a connection factory8Iconnectionfactory factory =New ConnectionFactory ("tcp://localhost:61616/");9using (iconnection connection =Factory.createconnection ())10{11//Create session12 using (ISession session =Connection.createsession ())13{14//Create producer producer for the Topic/queue15Imessageproducer prod =Session.createproducer (16New Apache.nms.activemq.commands.activemqtopic ("Testing"));17//Send Message18 int i =0;1920while (!console.keyavailable)21st{Itextmessage msg =Prod.createtextmessage ();Msg.text =i.ToString ();Console.WriteLine ("Sending:" +i.ToString ());25Prod.send (msg, apache.nms.msgdeliverymode.nonpersistent, Apache.nms.msgpriority.normal, Timespan.minvalue);26System.threading.thread.sleep (5000);i++;29}30}31}32 33 Console.ReadLine (); 34 }35 catch (System.Exception e) 36 {37 Console.WriteLine (" {0}" ,e.message); Console.ReadLine () }40 }41}
3. Writing Consumer Consumer code
1ClassProgram2{3Staticvoid Main (String[] args)4{5Try6{7//Create a connection factory8Iconnectionfactory factory =New ConnectionFactory ("tcp://localhost:61616/");9//Create a connection10 using (iconnection connection =Factory.createconnection ())11{Connection.clientid ="Testing Listener";13Connection.start ();14//Create session15 using (ISession session =Connection.createsession ())16{17//Create consumer18Imessageconsumer consumer = Session.createdurableconsumer (New Apache.nms.activemq.commands.activemqtopic ("Testing"),"Testing Listener",NullFalse);19//Binding events that receive messages20Consumer.listener + =NewMessageListener (Consumer_listener);21stConsole.ReadLine ();22}23Connection.stop ();24Connection.close ();25}26}27Catch(System.Exception e)28{29Console.WriteLine (E.message);30}31}3233StaticvoidConsumer_listener (IMessage message)34{35Try36 {37 itextmessage msg = ( itextmessage) message; 38 Console.WriteLine ( " Receive: "+ Msg.text); }40 catch (System.Exception e) 41 {42 Console.WriteLine (e.message); }44 }45}
Related parameter description
5. Related Parameters* (1) connection Factory iconnectionfactory
The connection factory is the object that the customer uses to create the connection.
* (2) connection iconnection
Iconnection encapsulates a virtual connection between a customer and a service
This article from: Macaidong Blog Reprint please specify the source URL: http://www.makaidong.com
。 * (3) Session sessions
A session is a single-threaded context for producing and consuming messages. Sessions are used to create message producers (producer), Message consumers (consumer), and messages (message), and so on. A session provides a transactional context in which a set of send and receive is combined into an atomic operation.
* (4) destination
A destination is an object that the customer uses to specify the destination of the message it produces and the source of the message it consumes. Two types of messaging domains are defined: Point-to-point (PTP) Messaging domains and publish/Subscribe messaging domains.
In a point-to-point messaging domain, the destination is queued (queue), and in the Publish/Subscribe messaging domain, the destination becomes the subject (topic).
* (5) message producer producer
A message producer is an object created by a session that sends a message to a destination.
* (6) Message consumer consumer
A message consumer is an object created by a session that is used to receive messages sent to a destination. Message consumption can take one of the following two methods:
Simultaneous consumption. The message is explicitly extracted from the destination by calling the consumer's receive method. The Receive method can be blocked until the message arrives.
Asynchronous consumption. Customers can register a message listener for the consumer to define the actions taken when the message arrives.
* (7) Message Itextmessage
The message consists of the following three parts: the message header. Each message header field has a corresponding getter and setter method. The message properties. If you need a value other than the message header field, you can use the message property. The message body. The message types defined are TextMessage, Mapmessage, Bytesmessage, Streammessage, and ObjectMessage.
Search articles related to this article:. NET use of ActivemqThis article link: http://www.makaidong.com/%E5%8D%9A%E5%AE%A2%E5%9B%AD%E7%83%AD%E6%96%87/11740.shtml reprint please indicate the source:. NET use of ACTIVEMQ-Blog Park
. NET platform under ACTIVEMQ