ActiveMQ--Broker 妖狐艹你老母 2021-08-13 18:46 351阅读 0赞 ### Broker ### 相当于一个ActiveMQ服务器实例。 Broker其实就是实现了用代码的形式启动ActiveMQ将MQ嵌入到Java中,以便随时用随时启动,在用的时候再去启动这样就节省了资源,也保证了可靠性。 嵌入式Broker: 用ActiveMQ Broker作为独立的消息服务器来构建JAVA应用。ActiveMQ也支持再vm中通信基于嵌入式的broker,能够无缝的集成其他java应用。 pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>ActiveMQPro</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.targer>1.8</maven.compiler.targer> </properties> <dependencies> <!-- avtivemq所需要的jar包 --> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.15.9</version> </dependency> <dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-spring</artifactId> <version>3.16</version> </dependency> <!-- broker --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.5</version> </dependency> <!-- junit/log4j等基础通用配置 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.18</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> </dependencies> </project> 编码: package pres.zhang.activemq; import org.apache.activemq.broker.BrokerService; /** * 嵌入式Broker */ public class EmbedBroker { public static void main(String[] args) throws Exception { BrokerService brokerService = new BrokerService(); brokerService.setUseJmx(true); brokerService.addConnector("tcp://localhost:61616"); brokerService.start(); } } ### 不同的conf配置文件模拟不同的实例 ### ![在这里插入图片描述][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NvbGRfX19wbGF5_size_16_color_FFFFFF_t_70] ![在这里插入图片描述][20200120232149517.png] ![在这里插入图片描述][20200120232155476.png] [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NvbGRfX19wbGF5_size_16_color_FFFFFF_t_70]: /images/20210813/041285a2efdc49c4a44a150927ad38c9.png [20200120232149517.png]: /images/20210813/3c78fba239d142e0a1fa0e2cc58db974.png [20200120232155476.png]: /images/20210813/6f13021467864b7ab5760787c1301fa6.png
还没有评论,来说两句吧...