Chapter 3. Deploying AMQ Broker on OpenShift Container Platform
The procedures in this section show how to prepare a broker deployment and an example of using the OpenShift Container Platform web console to deploy a basic broker instance. For examples of deploying other broker configurations, see Tutorials.
The following procedures assume that the broker image and application templates you installed in Installing AMQ Broker on OpenShift Container Platform are available in the global openshift project. If you installed the image and application templates in a specific project namespace, then continue to use that project instead of creating a new project such as amq-demo.
3.1. Preparing an AMQ Broker deployment Copy linkLink copied to clipboard!
Procedure
Use the command prompt to create a new project:
$ oc new-project amq-demoCreate a service account to be used for the AMQ Broker deployment:
$ echo '{"kind": "ServiceAccount", "apiVersion": "v1", "metadata": {"name": "amq-service-account"}}' | oc create -f -Add the view role to the service account. The view role enables the service account to view all the resources in the amq-demo namespace, which is necessary for managing the cluster when using the OpenShift dns-ping protocol for discovering the mesh endpoints.
$ oc policy add-role-to-user view system:serviceaccount:amq-demo:amq-service-accountAMQ Broker requires a broker keystore, a client keystore, and a client truststore that includes the broker keystore. This example uses Java Keytool, a package included with the Java Development Kit, to generate dummy credentials for use with the AMQ Broker installation.
Generate a self-signed certificate for the broker keystore:
$ keytool -genkey -alias broker -keyalg RSA -keystore broker.ksExport the certificate so that it can be shared with clients:
$ keytool -export -alias broker -keystore broker.ks -file broker_certGenerate a self-signed certificate for the client keystore:
$ keytool -genkey -alias client -keyalg RSA -keystore client.ksCreate a client truststore that imports the broker certificate:
$ keytool -import -alias broker -keystore client.ts -file broker_certUse the broker keystore file to create the AMQ Broker secret:
$ oc create secret generic amq-app-secret --from-file=broker.ksAdd the secret to the service account created earlier:
$ oc secrets add sa/amq-service-account secret/amq-app-secret
3.2. Deploying a basic broker Copy linkLink copied to clipboard!
Deploy a basic broker that is ephemeral and does not support SSL. This tutorial covers how to create transports, addresses, and queues.
This broker does not support SSL and is not accessible to external clients. Only clients running internally on the OpenShift cluster can connect to the broker. For examples of creating broker configurations that support SSL, see Tutorials.
Prequisites
3.2.1. Deploy the image and template Copy linkLink copied to clipboard!
Procedure
- Navigate to the OpenShift web console and log in.
-
Select the
amq-demoproject space, or another, existing project in which you want to deploy a broker. - Click Add to Project > Browse Catalog to list all of the default image streams and templates.
-
Use the Filter search bar to find results that match
amq. You might need to click See all to show the desired application template. -
Select the
amq-broker-73-basictemplate, which is labeledRed Hat AMQ Broker 7.3 (Ephemeral, no SSL). Set the following environment variables in the configuration and click Create.
Expand Table 3.1. Example template Environment variable Display Name Value Description AMQ_PROTOCOL
AMQ Protocols
openwire,amqp,stomp,mqtt,hornetq
The protocols to be accepted by the broker
AMQ_QUEUES
Queues
demoQueue
Creates an anycast queue called demoQueue
AMQ_ADDRESSES
Addresses
demoTopic
Creates a multicast address (or topic) called demoTopic
AMQ_USER
AMQ Username
amq-demo-user
The username the client uses
AMQ_PASSWORD
AMQ Password
password
The password the client uses with the username
You can also deploy the image from the command line:
$ oc new-app --template=amq-broker-73-basic \ -e AMQ_PROTOCOL=openwire,amqp,stomp,mqtt,hornetq \ -e AMQ_QUEUES=demoQueue \ -e AMQ_ADDRESSES=demoTopic \ -e AMQ_USER=amq-demo-user \ -e ADMIN_PASSWORD=password \
3.2.2. Deploy the application Copy linkLink copied to clipboard!
After the application is created, you need to deploy it. Deploying the application creates a pod and starts the broker.
Procedure
- After the deployment has been created, choose Deployments from the Applications menu.
- Click the broker-amq deployment.
Click Deploy to deploy the application.
NoteIf the application does not deploy, you can check the configuration by clicking the Events tab. If something is incorrect, edit the configuration by clicking the Action button.
- After the deployment has appeared on the list, click on it to view the state of the pods. Click on the pod and then click the Logs tab to view the broker logs and verify its state. You should see the queue previously created.
Click the Terminal tab to access a shell where you can use the CLI to test sending and consuming messages.
sh-4.2$ ./broker/bin/artemis producer Producer ActiveMQQueue[TEST], thread=0 Started to calculate elapsed time ... Producer ActiveMQQueue[TEST], thread=0 Produced: 1000 messages Producer ActiveMQQueue[TEST], thread=0 Elapsed time in second : 4 s Producer ActiveMQQueue[TEST], thread=0 Elapsed time in milli second : 4584 milli seconds sh-4.2$ ./broker/bin/artemis consumer Consumer:: filter = null Consumer ActiveMQQueue[TEST], thread=0 wait until 1000 messages are consumed Received 1000 Consumer ActiveMQQueue[TEST], thread=0 Consumed: 1000 messages Consumer ActiveMQQueue[TEST], thread=0 Consumer thread finishedYou can also use the OpenShift client to access the shell by using the pod name, as shown in the following example.
oc rsh broker-amq-1-9x89r