Active MQ C++ realizes communication
background knowledge:
ActiveMQ is an easy-to-use messaging middleware.
message middleware
Let's briefly introduce the message middleware, just have a basic understanding of it, the message middleware (MOM: Message Orient middleware).
Message middleware has many uses and advantages:
1. Transfer data from one application to another, or from one software module to another;
2. Responsible for establishing network communication channels for reliable data send.
3. Ensure that the data is not retransmitted or lost
4. Can realize cross-platform operation, and can provide data transmission services for software integration technicians on different operating systems
SQM
First of all, I will briefly introduce MQ. The English name of MQ is MessageQueue. The Chinese name is also the message queue that everyone uses. Why do you use it? To put it bluntly, it is a container for receiving and forwarding messages, which can be used for message push.
Let's enter our topic today and introduce ActiveMQ to you:
ActiveMQ
Brief overview of ActiveMQ
Apache ActiveMQ ™ is the most popular and powerful open source messaging and Integration Patterns server.
Apache ActiveMQ is fast, supports many Cross Language Clients and Protocols, comes with easy to use Enterprise Integration Patterns and many advanced features while fully supporting JMS 1.1 and J2EE 1.4.
ActiveMQ is produced by Apache, one of the most popular and powerful open source message bus. ActiveMQ is a JMS Provider implementation that fully supports JMS1.1 and J2EE 1.4 specifications. It is very fast, supports clients and protocols in multiple languages, and can be easily embedded into enterprise application environments with many advanced features.
When to use ActiveMQ?
- Integration between multiple projects
(1) Cross-platform
(2) Multilingual
(3) Multi-project - Reduce the coupling degree of modules between systems, decoupling
(1) Software scalability - System front and rear isolation
(1) Front and rear isolation, shielding high security area - Write clients in multiple languages and protocols. Languages: Java, C, C++, C#, Ruby, Perl, Python, PHP. Application Protocol: OpenWire, Stomp REST, WS Notification, XMPP, AMQP
- Full support for JMS1.1 and J2EE 1.4 specifications (persistence, XA messages, transactions)
- For the support of Spring, ActiveMQ can be easily embedded into the system using Spring, and also supports the features of Spring 2.0
- Passed the test of common J2EE servers (such as Geronimo, JBoss 4, GlassFish, WebLogic), and through the configuration of JCA 1.5 resource adaptors, ActiveMQ can be automatically deployed to any compatible J2EE 1.4 commercial server.
- Supports multiple transport protocols: in-VM, TCP, SSL, NIO, UDP, JGroups, JXTA
- Supports high-speed message persistence via JDBC and journal
- High-performance clustering, client-server, peer-to-peer, guaranteed by design
- Ajax support
- Support integration with Axis
- It is easy to call the embedded JMS provider for testing
ActiveMQ feature list
The default TCP connection port used by ActiveMQ is 61616
Application Scenario:
Message queues are widely used in large e-commerce websites, such as JD.com, Taobao, Qunar and other websites. The main function of the queue is to eliminate high concurrent access peaks and speed up the response speed of the website. In the case of not using the message queue, the user's request data is directly written to the database. In the case of high concurrency, it will cause huge pressure on the database and also increase the system response delay. After using the queue, the user's request is sent to the queue and returned immediately (of course, the user cannot be directly notified that the order has been submitted successfully, JD.com prompts: "You have submitted the order, please wait for the system to confirm"), and then the consumer of the message queue The process gets data from the message queue and writes it to the database asynchronously. Since the service processing speed of the message queue is much faster than that of the database, the response delay of the user can be effectively improved.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Steps
1. Download version
ActiveMQ-cpp-2.2.6
apr-1.6.2
apr-iconv-1.2.1
apr-util-1.6.0
2. The path is D:\GCN\MQClient\Activemq-cpp\tags
Remove the version number of the dependent library
apr-util ,apr-1.6.2 ,apr-iconv
3. Open D:\GCN\MQClient\Activemq-cpp\tags\activemq-cpp-2.2.6\vs2005-build
Compile dependencies as apr-util -> apr-iconv -> apr
- Precautions
When compiling to libaprutil, Debug depends on expat.lib, and release depends on xml.lib .
Debug:
E:\GCN\20170831SVN_MAIN\trunk\Product\MQClient\apr-util\xml\expat\lib
Release:
- Compile vs2005-activemq
Set up dependencies, attach library header files, and attach library lib paths.
- Compile vs2005-activemq-example
config file:
Vs2005-activemq-cpp.exe
activemq.cfg
##### Global configuration parameters######
host_id=35
node_id=3236
cmdline = 1
Consumer = 1 (Producer and Consumer switch)
#Configure restart
#reset_time = 0,20:00:00
reset_time = 06:15:00
sync_time = 0
sync_interval = 60
accept_sync_time = 0
#MQConfiguration
mq_url = tcp: //10.1.6.2: 61616
mq_user = jlt_mq
mq_pwd = jlt_mq123
mq_topic = jlt.srv.quote.engine.pubQuote.topic.queueName
#mq_topic = QUOTATION.WJF.TEST
#read shared queue
mem_que_name = QUEUE_MQ_SERVER
other_inst_multi = 1000
forex_inst_multi = 10000
#Write to the shared queue
XQUE_NUM = 2
XQUE1.XQUE_NAME = MQ_QUOTATION3
XQUE1.WAIT_PERMIT = 10000
XQUE1.BUFFER_PERMIT = 10000
XQUE1.MAIN = 1
XQUE1.MODE = 1
XQUE2.XQUE_NAME = MQ_QUOTATION4
XQUE2.XQUE_TIMEOUT = 1000
XQUE2.WAIT_PERMIT = 10000
XQUE2.BUFFER_PERMIT = 10000
XQUE2.MAIN = 1
XQUE2.MODE = 1