Maven2 ActiveMQ Classic Broker 外掛程式

工具 > Maven2 ActiveMQ Classic Broker 外掛程式

ActiveMQ Classic 提供了一個 Maven2 外掛程式,可以輕鬆啟動 JMS Broker。 它對於在您的 Maven2 專案中快速啟動訊息 Broker 以進行除錯或整合測試非常有用。

 如何使用

請小心

ActiveMQ Classic 中的 Maven 外掛程式在 5.8.0+ 版本中已重新命名,以更好地遵循 Maven 外掛程式的命名慣例。ActiveMQ Classic Broker 外掛程式已從 ‘maven-activemq-plugin’ 變更為 ‘activemq-maven-plugin’。

將 5.7.0 版本字串替換為您選擇的版本,例如:5.6.0、5.8-SNAPSHOT

在您的 Maven2 專案中,或使用如下的最小 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.acme</groupId>
  <artifactId>run-amq</artifactId>
  <version>1.0-SNAPSHOT</version>
</project>

只需輸入

mvn org.apache.activemq.tooling:maven-activemq-plugin:5.1:run

這將下載 5.7.0 版本的外掛程式,並使用簡單的組態 URL 啟動 Broker,格式為 broker:(tcp://127.0.0.1:61616)?useJmx=false&persistent=false。必要的 ActiveMQ Classic jar 將由 Maven 自動下載。

若要組態 log4j,請在 mvn 命令列上提供 -Dlog4j.configuration=[file:///](file:///)<log4j.properties 的完整路徑> 系統屬性。

如果您需要更進階的組態,支援 Spring、Jetty Web Console 或內嵌 Camel,您可以在 pom.xml 中新增外掛程式並提供所需的選擇性相依性。對於預設的 conf/activemq.xml,需要以下相依性

 <build>    
    <plugins>
      <plugin>
        <groupId>org.apache.activemq.tooling</groupId>
        <artifactId>maven-activemq-plugin</artifactId>
        <version>5.7.0</version>
        <configuration>
          <configUri>xbean:file:../conf/activemq.xml</configUri>
          <fork>false</fork>
          <systemProperties>
            <property>
              <name>javax.net.ssl.keyStorePassword</name>
              <value>password</value>
            </property>
            <property>
              <name>org.apache.activemq.default.directory.prefix</name>
              <value>./target/</value>
            </property>
          </systemProperties>
        </configuration>
        <dependencies>
			  <dependency>
		      <groupId>org.springframework</groupId>
			    <artifactId>spring</artifactId>
		      <version>2.5.5</version>
			  </dependency>
			  <dependency>
		      <groupId>org.mortbay.jetty</groupId>
		      <artifactId>jetty-xbean</artifactId>
		      <version>6.1.11</version>
		    </dependency> 	
		    <dependency>
		      <groupId>org.apache.camel</groupId>
		      <artifactId>camel-activemq</artifactId>
		      <version>1.1.0</version>
        </dependency>
      </dependencies>			
    </plugin>
  </plugins>
</build>
``
 and run it using:

mvn activemq:run ```

 組態選項

名稱 預設值 描述
configUri broker:(tcp://127.0.0.1:61616)?useJmx=false&persistent=false 將用於啟動 Broker 的 Broker 組態 URI。 更多資訊,請參考此處
fork false 如果為 true,則在單獨的執行緒中啟動 Broker,使 Maven 能夠繼續處理(對於整合測試很有用)。
systemProperties 將設定的其他系統屬性。

注意:預設情況下,Broker 外掛程式會將 activemq.base、activemq.home、org.apache.activemq.default.directory.prefix、derby.system.home 設定為 ./target/。這表示所有資料夾都將在那裡建立,因此可以透過執行 mvn clean 輕鬆刪除。

Apache、ActiveMQ、Apache ActiveMQ、Apache 羽毛標誌和 Apache ActiveMQ 專案標誌是 The Apache Software Foundation 的商標。 版權 © 2024,The Apache Software Foundation。 根據 Apache License 2.0 授權。