Getting started with ActiveMQ isn’t difficult. You simply need to start up the broker and make sure that it’s capable of accepting connections and sending messages. ActiveMQ comes with some simple examples that will help you with this task, but first we need to install Java and download ActiveMQ.
In this section, you’ll download and install ActiveMQ, examine the ActiveMQ directory, and start up ActiveMQ for the first time. (Assume Java SE is ready)
ActiveMQ is available from the Apache ActiveMQ website at the following URL: http://activemq.apache.org/download.html. Click on the link to the 5.4.1 release and you’ll find both tarball and zip formats available (the tarball is for Linux and Unix; the zip is for Windows). Once you’ve downloaded one of the archives, expand it and you’re ready to move along. Once you get to this point, you should have the Java SE all set up and working correctly, and you’re ready to take a peek at the ActiveMQ directory.
Examining the ActiveMQ directory:
From the command line, move into the apache-activemq-5.x.x directory and enter the command shown here.
- Listing 1.2 List the contents of the ActiveMQ directory
The contents of the directory are fairly straightforward:
The next task is to start up ActiveMQ and verify it using the examples.
Starting up ActiveMQ:
After downloading and expanding the archive, ActiveMQ is ready for use. The binary distribution provides a basic configuration to get you started easily and that’s what we’ll use in the examples. So start up ActiveMQ now as shown next.
- Listing 1.3 Start up ActiveMQ
This command starts up the ActiveMQ broker and some of its connectors to expose it to clients via a few protocols, namely, TCP, SSL, STOMP, and XMPP. Just be aware that ActiveMQ has started and is available to clients via TCP on port 61616. This is all configurable and will be discussed later in chapter 4. For now, the preceding output tells you that ActiveMQ is up and running and ready for use. Now it’s ready to begin handling some messages. The best way to begin sending and receiving messages is by using some of the examples that come with ActiveMQ. The next section walks you through this in a step-by-step manner.
Running your first examples with ActiveMQ:
The previous section walked you through starting up ActiveMQ in one terminal. For verification of this, you should open two more terminals to run the ActiveMQ examples. In the second terminal, move into the example directory and look at its contents as shown in the following listing.
- Listing 1.4 List the contents of the ActiveMQ example directory
The example directory contains a few different items. Here’s a quick description of each item in that directory:
Using the second terminal, start up a JMS consumer as shown here.
- Listing 1.5 Start up the ActiveMQ consumer example
The command compiles the Java examples and starts up a simple JMS consumer. As you can see from the output, this consumer is
Basically, the JMS consumer is connected to ActiveMQ and waiting for messages. Now you can send some messages to the TEST.FOO destination.
In the third terminal, move into the example directory and start up a JMS producer as shown below. This will immediately begin to send messages.
- Listing 1.6 Start up the ActiveMQ producer example
Although the output has been truncated for readability, the command starts up a simple JMS producer and you can see from the output that it
Once the JMS producer is connected, it then sends 2,000 messages and shuts down. This is the number of messages the consumer is waiting to consume before it shuts down. So as the messages are being sent by the producer in terminal three, flip back to terminal two and watch the JMS consumer as it consumes those messages. Here’s the output you’ll see in terminal two:
At this time, both the consumer and the producer should be shut down, but the ActiveMQ broker is still running in the first terminal. Take a look at the first terminal again and you’ll see that ActiveMQ appears to not have budged at all. This is because the default logging configuration doesn’t output anything beyond what’s absolutely necessary. If you’d like to tweak the logging configuration to output more information as messages are sent and received, you can do so. Logging will be covered further in chapter 14.
Through the use of the Java examples that come with ActiveMQ, it has been proven that the broker is up and running and can mediate messages. This doesn’t seem like much but it’s an important first step. If you were able to successfully run the Java examples, then you know that you have no networking problems on the machine you’re using and you know that ActiveMQ is behaving properly. If you were unable to successfully run the Java examples, then you’ll need to troubleshoot the situation. If you need some help, heading over to the ActiveMQ mailing lists is the best way to find help. These examples are just to get you started but can be used to test many scenarios. Throughout the rest of the book, some different examples surrounding a couple of common use cases will be used to demonstrate ActiveMQ and its features. These examples are explained further in chapter 3.
- [ 英文學習 ]
- [ 計算機概論 ]
- [ 深入雲計算 ]
- [ 雜七雜八 ]
- [ Algorithm in Java ]
- [ Data Structures with Java ]
- [ IR Class ]
- [ Java 文章收集 ]
- [ Java 代碼範本 ]
- [ Java 套件 ]
- [ JVM 應用 ]
- [ LFD Note ]
- [ MangoDB ]
- [ Math CC ]
- [ MongoDB ]
- [ MySQL 小學堂 ]
- [ Python 考題 ]
- [ Python 常見問題 ]
- [ Python 範例代碼 ]
- [C 常見考題]
- [C 範例代碼]
- [C/C++ 範例代碼]
- [Intro Alg]
- [Java 代碼範本]
- [Java 套件]
- [Linux 命令]
- [Linux 小技巧]
- [Linux 小學堂]
- [ML In Action]
- [Python 學習筆記]
- [Quick Python]
- [Software Engineering]
- [The python tutorial]
- ActiveMQ In Action
- Big Data 研究
- Design Pattern
- Device Driver Programming
- Docker 工具
- Docker Practice
- English Writing
- ExtJS 3.x
- Git Pro
- Hadoop. Hadoop Ecosystem
- Java Framework
- Java UI
- Learn Spark
- ML Udemy
- Python Std Library
- Python tools
- Ruby Packages
- Windows 技巧
Preface This chapter covers: ( Functional Programming in Java ) * The benefits of functional programming * Problems with side ef...
來源自 這裡 前言 : Thread 是 threading 模塊中最重要的類之一，可以使用它來創建線程。有兩種方式來創建線程：一種是通過繼承Thread 類，重寫它的 run 方法；另一種是創建一個 threading.Thread 對象，在它的初始化...
Preface: 在這個階層中，我們只需考慮電路模組的功能，而不需考慮其硬體的詳細內容. Verilog 的時序控制為以事件為基礎的時序控制: * 接線或暫存器的值被改變。 * 模組的輸入埠接收到新的值 * 正規...
轉載自 這裡 前言 : 這裡簡單說明了 #define 的幾種使用方法. 簡單的define定義 : #define MAXTIME 1000 一個簡單的MAXTIME就定義好了，它代表1000，如果在程序裡面寫 : int i = MAXTIME; ...