ActiveMQ Connection visualisation

http://activemq.apache.org/visualisation.html

Step 1 : Add plugin into activemq.xml


<plugins>  
          <connectionDotFilePlugin  file="connection.dot"/>  
</plugins> 

Step 2: Run AcitveMQServer

Step 3: Get " connection.dot" file under " C:/apache-activemq-5.5.0/bin/win32/"

C:/apache-activemq-5.5.0/bin/win32/connection.dot

Step 4: Install zgrviewer and Graphviz


Step 5: Config zgrviewer to link to ".dot" and " Graphviz"









 

ActiveMQ中,有两种方式可以连接到队列并进行消息监听: 1. 使用JMS API连接 JMS API是Java Message Service的缩写,是Java中用于发送和接收消息的标准API。使用JMS API连接ActiveMQ时,需要使用ActiveMQ提供的JAR包,并在代码中通过JMS API创建连接、会话和消息消费者。以下是一个简单的示例代码: ```java import org.apache.activemq.ActiveMQConnectionFactory; import javax.jms.*; public class Consumer { public static void main(String[] args) throws JMSException { // 创建连接工厂对象 ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); // 创建连接对象 Connection connection = connectionFactory.createConnection(); // 启动连接 connection.start(); // 创建会话对象 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // 创建队列对象 Queue queue = session.createQueue("test-queue"); // 创建消息消费者对象 MessageConsumer consumer = session.createConsumer(queue); // 设置消息监听器 consumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { // 处理消息 System.out.println("Received message: " + ((TextMessage) message).getText()); } catch (JMSException e) { e.printStackTrace(); } } }); } } ``` 2. 使用ActiveMQ提供的Spring集成 ActiveMQ提供了一个Spring集成框架,可以通过配置文件来连接ActiveMQ并监听队列。使用Spring集成时,需要在配置文件中定义连接工厂、队列和消息监听器等组件。以下是一个简单的示例配置文件: ```xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> <!-- 定义ActiveMQ连接工厂 --> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616"/> </bean> <!-- 定义队列 --> <amq:queue id="testQueue" physicalName="test-queue"/> <!-- 定义消息监听器 --> <bean id="messageListener" class="com.example.MessageListener"/> <!-- 定义消息容器 --> <amq:listener-container connection-factory="connectionFactory"> <amq:listener destination="testQueue" ref="messageListener"/> </amq:listener-container> </beans> ``` 在以上配置文件中,定义了连接工厂、队列、消息监听器和消息容器。其中,消息监听器是一个Java类,实现了MessageListener接口,用于处理接收到的消息。消息容器会自动创建连接、会话和消息消费者,并将消息交给消息监听器处理。需要注意的是,使用Spring集成时需要在项目中引入相关的Spring和ActiveMQ依赖。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值