Apache ActiveMQ - 测试应用主题

启动 ActiveMQ 服务器

现在让我们启动 ActiveMQ 服务器。 转到文件夹 F:/ → Apache → apache-activemq-5.16.4/bin 并键入以下命令。


示例

F:\Apache\apache-activemq-5.16.4\bin>activemq start

输出

您将看到类似的输出,ActiveMQ 将开始运行。

...
INFO | Apache ActiveMQ 5.16.4 (localhost, ID:DESKTOP-86KD9FC-52669-1645860020983-0:1) started
INFO | For help or more information please see: http://activemq.apache.org
INFO | ActiveMQ WebConsole available at http://127.0.0.1:8161/
INFO | ActiveMQ Jolokia REST API available at http://127.0.0.1:8161/api/jolokia/

启动发布者应用程序

在 Eclipse 中,右键单击 Publisher.java 源,然后选择 Run As → Java Application。 Publisher 应用程序将开始运行,您将看到如下输出 −

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Enter message:

Start the Subscriber Application

In eclipse, right click on the Subscriber.java source, and select Run As → Java Application. Subscriber application will start running and you'll see the output as follows −

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

启动另一个订阅者应用程序

在 Eclipse 中,再次右键单击 Subscriber.java 源,然后选择 Run As → Java Application。 另一个订阅者应用程序将开始运行,您将看到如下输出 −

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

发送消息

在 Publisher 控制台窗口中,输入 Hi 并按回车键发送消息。

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Enter message:
Hi

接收消息

在订阅者控制台窗口中验证,每个窗口都会收到消息。

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Received = Hi

发送 Quit 作为消息以终止所有发布者和订阅者控制台窗口会话。


验证

现在在浏览器中打开 http://127.0.0.1:8161/admin/。 它将要求提供凭据。 使用 admin/admin 作为用户名/密码,它将加载 ActiveMQ 管理控制台,您可以在其中检查主题以检查状态。 它将显示多条消息入队和传递。

主题