Chapter 2. Getting started
This guide describes the process of setting up AMQ Online on OpenShift with clients for sending and receiving messages to evaluate its potential use in a production environment.
Prerequisites
To install AMQ Online, the OpenShift Container Platform command-line interface (CLI) is required.
- For more information about how to install the CLI on OpenShift 3.x, see the OpenShift Container Platform 3.11 documentation.
- For more information about how to install the CLI on OpenShift 4.1, see the OpenShift Container Platform 4.1 documentation.
- An OpenShift cluster is required.
-
A user on the OpenShift cluster with
cluster-admin
permissions is required to set up the required cluster roles and API services.
2.1. Installing AMQ Online using a YAML bundle
After completing the download and installation procedures, you must then:
2.1.1. Downloading AMQ Online
Procedure
-
Download and extract the
amq-online-install.zip
file from the AMQ Online download site.
Although container images for AMQ Online are available in the Red Hat Container Catalog, we recommend that you use the YAML files provided instead.
2.1.2. Installing AMQ Online using a YAML bundle
The simplest way to install AMQ Online is to use the predefined YAML bundles.
Procedure
Log in as a user with
cluster-admin
privileges:oc login -u system:admin
(Optional) If you want to deploy to a project other than
amq-online-infra
you must run the following command and substituteamq-online-infra
in subsequent steps:sed -i 's/amq-online-infra/my-project/' install/bundles/amq-online/*.yaml
Create the project where you want to deploy AMQ Online:
oc new-project amq-online-infra
- Change the directory to the location of the downloaded release files.
Deploy using the
amq-online
bundle:oc apply -f install/bundles/amq-online
(Optional) Install the example plans and infrastructure configuration:
oc apply -f install/components/example-plans
(Optional) Install the example roles:
oc apply -f install/components/example-roles
(Optional) Install the
standard
authentication service:oc apply -f install/components/example-authservices/standard-authservice.yaml
(Optional) Install the Service Catalog integration:
oc apply -f install/components/service-broker oc apply -f install/components/cluster-service-broker
2.2. Installing and configuring AMQ Online using the Operator Lifecycle Manager
You can use the Operator Lifecycle Manager to install and configure an evaluation instance of AMQ Online.
In OpenShift Container Platform 4.1, the Operator Lifecycle Manager (OLM) helps users install, update, and manage the life cycle of all Operators and their associated services running across their clusters. It is part of the Operator Framework, an open source toolkit designed to manage Kubernetes native applications (Operators) in an effective, automated, and scalable way.
The OLM runs by default in OpenShift Container Platform 4.1, which aids cluster administrators in installing, upgrading, and granting access to Operators running on their cluster. The OpenShift Container Platform console provides management screens for cluster administrators to install Operators, as well as grant specific projects access to use the catalog of Operators available on the cluster.
OperatorHub is the graphical interface that OpenShift cluster administrators use to discover, install, and upgrade Operators. With one click, these Operators can be pulled from OperatorHub, installed on the cluster, and managed by the OLM, ready for engineering teams to self-service manage the software in development, test, and production environments.
2.2.1. Installing AMQ Online from the OperatorHub using the OpenShift Container Platform console
You can install the AMQ Online Operator on an OpenShift Container Platform 4.1 cluster by using OperatorHub in the OpenShift Container Platform console.
You must install and deploy the AMQ Online Operator in the openshift-operator
project.
Prerequisites
-
Access to an OpenShift Container Platform 4.1 cluster using an account with
cluster-admin
permissions.
Procedure
-
In the OpenShift Container Platform console, log in using an account with
cluster-admin
privileges. - Click Operators > OperatorHub.
-
In the Filter by keyword box, type
AMQ Online
to find the AMQ Online Operator. - Click the AMQ Online Operator. Information about the Operator is displayed.
- Read the information about the Operator and click Install. The Create Operator Subscription page opens.
On the Create Operator Subscription page, accept all of the default selections and click Subscribe.
NoteAll namespaces on the cluster (default) installs the Operator in the default openshift-operators project and makes the Operator available to all projects in the cluster.
The amq-online page is displayed, where you can monitor the installation progress of the AMQ Online Operator subscription.
After the subscription upgrade status is shown as Up to date, click Operators > Installed Operators to verify that the AMQ Online ClusterServiceVersion (CSV) is displayed and its Status ultimately resolves to InstallSucceeded in the openshift-operators project.
NoteFor the All namespaces… installation mode, the status resolves to InstallSucceeded in the openshift-operators project, but the status is Copied if you view other projects.
For troubleshooting information, see the OpenShift Container Platform documentation.
2.2.2. Configuring AMQ Online using the OpenShift Container Platform console
After installing AMQ Online from the OperatorHub using the OpenShift Container Platform console, create a new instance of a custom resource for the following items within the openshift-operators
project:
- service infrastructure configuration for an address space type (the example uses the standard address space type)
- an authentication service
- an address space plan
- an address plan
After creating the new instances of the custom resources, next:
The following procedures use the example data that is provided when using the OpenShift Container Platform console.
2.2.2.1. Creating an infrastructure configuration custom resource using the OpenShift Container Platform console
You must create an infrastructure configuration custom resource to use AMQ Online. This example uses StandardInfraConfig
for a standard address space.
Procedure
- In the top right, click the Plus icon (+). The Import YAML window opens.
-
From the top left drop-down menu, select the
amq-online-infra
project. Copy the following code:
apiVersion: admin.enmasse.io/v1beta1 kind: StandardInfraConfig metadata: name: default
- In the Import YAML window, paste the copied code and click Create. The StandardInfraConfig overview page is displayed.
- Click Operators > Installed Operators.
- Click the AMQ Online Operator and click the Standard Infra Config tab to verify that its Status displays as Active.
2.2.2.2. Creating an authentication service custom resource using the OpenShift Container Platform console
You must create a custom resource for an authentication service to use AMQ Online. This example uses the standard authentication service.
Procedure
- In the top right, click the Plus icon (+). The Import YAML window opens.
-
From the top left drop-down menu, select the
amq-online-infra
project. Copy the following code:
apiVersion: admin.enmasse.io/v1beta1 kind: AuthenticationService metadata: name: standard-authservice spec: type: standard
- In the Import YAML window, paste the copied code and click Create. The AuthenticationService overview page is displayed.
-
Click Workloads > Pods. In the Readiness column, the Pod status is
Ready
when the custom resource has been deployed.
2.2.2.3. Creating an address space plan custom resource using the OpenShift Container Platform console
You must create an address space plan custom resource to use AMQ Online. This procedure uses the example data that is provided when using the OpenShift Container Platform console.
Procedure
- In the top right, click the Plus icon (+). The Import YAML window opens.
-
From the top left drop-down menu, select the
amq-online-infra
project. Copy the following code:
apiVersion: admin.enmasse.io/v1beta2 kind: AddressSpacePlan metadata: name: standard-small spec: addressSpaceType: standard infraConfigRef: default addressPlans: - standard-small-queue resourceLimits: router: 2.0 broker: 3.0 aggregate: 4.0
- In the Import YAML window, paste the copied code and click Create. The AddressSpacePlan overview page is displayed.
- Click Operators > Installed Operators.
- Click the AMQ Online Operator and click the Address Space Plan tab to verify that its Status displays as Active.
2.2.2.4. Creating an address plan custom resource using the OpenShift Container Platform console
You must create an address plan custom resource to use AMQ Online. This procedure uses the example data that is provided when using the OpenShift Container Platform console.
Procedure
- In the top right, click the Plus icon (+). The Import YAML window opens.
-
From the top left drop-down menu, select the
amq-online-infra
project. Copy the following code:
apiVersion: admin.enmasse.io/v1beta2 kind: AddressPlan metadata: name: standard-small-queue spec: addressType: queue resources: router: 0.01 broker: 0.1
- In the Import YAML window, paste the copied code and click Create. The AddressPlan overview page is displayed.
- Click Operators > Installed Operators.
- Click the AMQ Online Operator and click the Address Plan tab to verify that its Status displays as Active.
2.3. Creating address spaces using the command line
In AMQ Online, you create address spaces using standard command-line tools.
Procedure
Log in as a messaging tenant:
oc login -u developer
Create the project for the messaging application:
oc new-project myapp
Create an address space definition:
apiVersion: enmasse.io/v1beta1 kind: AddressSpace metadata: name: myspace spec: type: standard plan: standard-unlimited
Create the address space:
oc create -f standard-address-space.yaml
Check the status of the address space:
oc get addressspace myspace -o jsonpath={.status.isReady}
The address space is ready for use when the previous command outputs
true
.
2.4. Creating addresses using the command line
You can create addresses using the command line.
Procedure
Create an address definition:
apiVersion: enmasse.io/v1beta1 kind: Address metadata: name: myspace.myqueue spec: address: myqueue type: queue plan: standard-small-queue
NotePrefixing the name with the address space name is required to ensure addresses from different address spaces do not collide.
Create the address:
oc create -f standard-small-queue.yaml
List the addresses:
oc get addresses -o yaml
2.5. Creating users using the command line
In AMQ Online users can be created using standard command-line tools.
Prerequisites
- You must have already created an address space.
Procedure
To correctly base64 encode a password for the user definition file, run the following command:
echo -n password | base64 #cGFzc3dvcmQ=
NoteBe sure to use the
-n
parameter when running this command. Not specifying that parameter will result in an improperly coded password and cause log-in issues.Save the user definition to a file:
apiVersion: user.enmasse.io/v1beta1 kind: MessagingUser metadata: name: myspace.user1 spec: username: user1 authentication: type: password password: cGFzc3dvcmQ= # Base64 encoded authorization: - addresses: ["myqueue", "queue1", "queue2", "topic*"] operations: ["send", "recv"] - addresses: ["anycast1"] operations: ["send"]
Create the user and associated user permissions:
oc create -f user-example1.yaml
Confirm that the user was created:
oc get messagingusers
2.6. Sending and receiving messages
Prerequisites
- Installed Apache Qpid Proton Python bindings.
-
An address space named
myspace
must be created. -
An address named
myqueue
must be created. -
A user named
user1
with passwordpassword
must be created.
Procedure
Save Python client example to a file:
from __future__ import print_function, unicode_literals import optparse from proton import Message from proton.handlers import MessagingHandler from proton.reactor import Container class HelloWorld(MessagingHandler): def __init__(self, url): super(HelloWorld, self).__init__() self.url = url def on_start(self, event): event.container.create_receiver(self.url) event.container.create_sender(self.url) def on_sendable(self, event): event.sender.send(Message(body="Hello World!")) event.sender.close() def on_message(self, event): print("Received: " + event.message.body) event.connection.close() parser = optparse.OptionParser(usage="usage: %prog [options]") parser.add_option("-u", "--url", default="amqps://localhost:5672/myqueue", help="url to use for sending and receiving messages") opts, args = parser.parse_args() try: Container(HelloWorld(opts.url)).run() except KeyboardInterrupt: pass
Retrieve the address space messaging endpoint host name:
oc get addressspace myspace -o 'jsonpath={.status.endpointStatuses[?(@.name=="messaging")].externalHost}'
Use the output as the host name in the following step.
Run the client:
python client-example1.py -u amqps://user1:password@messaging.example1.com:443/myqueue