舊版 OSGi 整合

連線能力 > 容器 > 舊版 OSGi 整合

本文適用於 5.4.0 之前的 ActiveMQ Classic 版本。如果您使用 5.4.0 或更新版本,請繼續閱讀以下文章

簡介

所有 ActiveMQ Classic 模組都封裝為 OSGi 套件,可以在任何 OSGi 容器中使用。本文將提供關於如何在 Apache Karaf(小型基於 OSGi 的執行環境)中使用 ActiveMQ Classic 的更多詳細資訊。Apache Karaf 以前稱為ServiceMix 核心,因此這裡找到的資訊也適用於 Apache ServiceMix 企業服務匯流排

ActiveMQ Classic

ActiveMQ Classic 作為 ServiceMix (Karaf) 的一個功能提供。因此,您只需使用單一命令即可安裝它,而不是逐個安裝所有必要的套件。但首先,您需要設定 ServiceMix 功能網址。

smx@root:/> features/addUrl mvn:org.apache.servicemix/apache-servicemix/4.0.0/xml/features

現在您可以像這樣安裝 ActiveMQ Classic

smx@root:/> features/install activemq

此命令將安裝所有必要的 ActiveMQ Classic 套件,如果您輸入

smx@root:/> osgi/list

您應該會看到類似這樣的內容

[  50] [Active     ] [       ] [   60] geronimo-jta\_1.1\_spec (1.1.1)
[  51] [Active     ] [       ] [   60] geronimo-j2ee-connector\_1.5\_spec (2.0.0)
[  52] [Active     ] [       ] [   60] Apache ServiceMix Bundles: howl-1.0.1-1 (1.0.1.1_1)
[  53] [Active     ] [       ] [   60] Geronimo TxManager :: Transaction (2.2.0.r634076)
[  54] [Active     ] [       ] [   60] Spring Transaction (2.5.6)
[  55] [Active     ] [Started] [   60] Apache ServiceMix Transaction (1.0.0)
[  56] [Active     ] [       ] [   60] Geronimo TxManager :: Connector (2.2.0.r634076)
[  57] [Active     ] [       ] [   60] geronimo-jms\_1.1\_spec (1.1.1)
[  58] [Active     ] [       ] [   60] Apache ServiceMix Bundles: jencks-2.1 (2.1.0.1)
[  59] [Active     ] [       ] [   60] geronimo-j2ee-management\_1.1\_spec (1.0.1)
[  60] [Active     ] [       ] [   60] Apache Commons Pool Bundle (1.4)
[  61] [Active     ] [       ] [   60] xbean-spring (3.5)
[  62] [Active     ] [       ] [   60] activemq-core (5.2.0)
[  63] [Active     ] [       ] [   60] activemq-ra (5.2.0)
[  64] [Active     ] [       ] [   60] activemq-console (5.2.0)
[  65] [Active     ] [       ] [   60] activemq-pool (5.2.0)
[  66] [Active     ] [Started] [   60] Apache ServiceMix Features :: ActiveMQ Commands (4.0.0)

安裝完成後,此功能提供一組特殊的命令,可讓您輕鬆使用代理程式。

此功能預先安裝在 ServiceMix ESB 中,因此先前的步驟不是必要的。

以下範例示範如何使用 create-brokerdestroy-broker 命令建立和銷毀代理程式。

smx@root:/> activemq/create-broker
Creating file: /Users/dejanb/workspace/apache-servicemix-kernel-1.1.0/deploy/localhost-broker.xml

在以下位置建立預設 ActiveMQ 代理程式 (localhost) 設定檔:/Users/dejanb/workspace/apache-servicemix-kernel-1.1.0/deploy/localhost-broker.xml 請檢閱設定並修改以符合您的需求。

smx@root:/> activemq/destroy-broker

已移除在以下位置建立的預設 ActiveMQ 代理程式 (localhost) 設定檔:/Users/dejanb/workspace/apache-servicemix-kernel-1.1.0/deploy/localhost-broker.xml。

有關 ActiveMQ Classic 功能的更多資訊,請參閱ServiceMix ActiveMQ Classic 整合指南

Web 主控台

Web 主控台包含在 ActiveMQ Classic 發行版中,您可能希望使用它來監控您的代理程式。首先,您必須安裝 web 功能,以便準備好可部署我們 Web 應用程式的 Web 容器。若要執行此操作,您應該先新增 ServiceMix 功能網址,就像我們上面所做的那樣(如果您尚未執行此操作)。現在,您可以直接執行

smx@root:/> features/install web

來擷取所有必要的套件。如果您輸入

smx@root:/> osgi/list

您將看到所有已安裝的套件(例如)

[  43] [Active     ] [       ] [   60] Apache ServiceMix Bundles: jetty-6.1.14 (6.1.14.1)
[  44] [Active     ] [       ] [   60] OPS4J Pax Web - Jsp Support (0.5.2)
[  45] [Active     ] [       ] [   60] OPS4J Pax Web - Web Container (0.5.2)
[  46] [Active     ] [       ] [   60] OPS4J Pax Web Extender - WAR (0.5.0)
[  47] [Active     ] [       ] [   60] OPS4J Pax Web Extender - Whiteboard (0.5.0)
[  48] [Active     ] [       ] [   60] OPS4J Pax Url - war:, war-i: (0.3.3)
[  49] [Active     ] [Started] [   60] Apache ServiceMix WAR Deployer (4.0.0)

此功能預先安裝在 ServiceMix ESB 中,因此先前的步驟不是必要的。

重要的是,我們需要使用正確版本的 Pax Web 套件才能使所有這些正常工作,而這些版本是

  • pax-web-bundle 版本 0.6.0
  • pax-web-jsp 版本 0.6.0
  • pax-web-ex-war 版本 0.5.1
  • pax-web-ex-whiteboard 版本 0.5.1

因此,如果您有較舊的套件,例如我們的範例中的情況,您需要解除安裝它們並安裝新的套件。若要解除安裝舊套件,只需查看其 ID 並執行

smx@root:/> osgi/uninstall [id]

在此範例中,它將是

smx@root:/> osgi/uninstall 44
smx@root:/> osgi/uninstall 45
smx@root:/> osgi/uninstall 46
smx@root:/> osgi/uninstall 47

現在安裝新的套件

smx@root:/> osgi/install mvn:org.ops4j.pax.web/pax-web-bundle/0.6.0
smx@root:/> osgi/install mvn:org.ops4j.pax.web/pax-web-jsp/0.6.0
smx@root:/> osgi/install mvn:org.ops4j.pax.web-extender/pax-web-ex-war/0.5.1
smx@root:/> osgi/install mvn:org.ops4j.pax.web-extender/pax-web-ex-whiteboard/0.5.1

成功安裝後,您應該啟動新新增的套件。您可以透過執行來完成此操作

smx@root:/> osgi/start [id]

最好在這時重新啟動您的容器,然後我們終於準備好部署我們的 war。為此,我們將使用 Pax Web War Extender。以下範例將使用最新的 5.3-SNAPSHOT 組建並將其部署在 OSGi 執行環境中

smx@root:/> osgi/install war:mvn:org.apache.activemq/activemq-web-console/5.3-SNAPSHOT/war?Webapp-Context=activemqweb

您必須使用最新的 5.3-SNAPSHOT Web 主控台,因為它無法與先前版本正常運作。

此外,如果您在透過先前方法安裝 war 時遇到問題,請從 https://repository.apache.org/content/repositories/snapshots/org/apache/activemq/activemq-web-console/5.3-SNAPSHOT/ 手動下載,並使用以下方法安裝

smx@root:/> osgi/install war:file:///path\_to\_the_war/activemq-web-console-5.3-SNAPSHOT.war?Webapp-Context=activemqweb

不幸的是,命令

osgi/install \
war:mvn:https://repository.apache.org/content/repositories/snapshots@snapshots!org.apache.activemq/activemq-web-console/5.3-SNAPSHOT/war?Webapp-Context=activemqweb

無法與 pax web war extender 0.5.1 搭配使用,但如果您使用的是較新版本,則可以嘗試使用它。

如果您執行

smx@root:/> osgi/list

您將在此處看到新新增的套件。

[  84] [Resolved   ] [       ] [   60] mvn\_org.apache.activemq\_activemq-web-console\_5.3-SNAPSHOT\_war (0)

現在是啟動它的時候了

smx@root:/> osgi/start 84

使用您套件的 ID

這裡需要注意的重要一點是,預設情況下,Web 主控台將啟動一個內嵌代理程式並對其進行監控。因此,如果您已在執行代理程式,則將無法啟動。

請注意,我們在部署 war 時使用了 activemqweb 作為 WebApp-Context,因此該主控台將在 https://127.0.0.1:8080/activemqweb 上可用。請瀏覽此 URL 並管理您的內嵌代理程式。

您很可能不想監控內嵌代理程式,而是監控您單獨啟動的代理程式(在 OSGi 執行環境或其他位置)。若要將您的 Web 主控台設定為執行此操作,您必須執行以下操作。首先,結束您的 OSGi 執行環境。現在您可以編輯 etc/system.properties 檔案並新增一些組態詳細資訊。以下組態片段

webconsole.type=properties
webconsole.jms.url=tcp://127.0.0.1:61616
webconsole.jmx.url=service:jmx:rmi:///jndi/rmi://127.0.0.1:1099/karaf-root
webconsole.jmx.user=karaf
webconsole.jmx.password=karaf

應適用於在 Karaf (ServiceMix) 中啟動的預設代理程式。請根據您的特定需求進行調整。

現在,如果您執行執行環境(和主控台套件),您會注意到主控台不會啟動代理程式,而是會嘗試使用系統屬性定義的代理程式。

請瀏覽 https://127.0.0.1:8080/activemqweb 並享受。

Apache、ActiveMQ、Apache ActiveMQ、Apache 羽毛標誌和 Apache ActiveMQ 專案標誌是 Apache 軟體基金會的商標。 版權所有 © 2024,Apache 軟體基金會。 根據 Apache 授權 2.0 授權。