此内容没有您所选择的语言版本。

Chapter 3. Accessing ActiveMQ using Skupper


Use public cloud resources to process data from a private message broker

This example is part of a suite of examples showing the different ways you can use Skupper to connect services across cloud providers, data centers, and edge sites.

Overview

This example is a simple messaging application that shows how you can use Skupper to access an ActiveMQ broker at a remote site without exposing it to the public internet.

It contains two services:

  • An ActiveMQ broker running in a private data center. The broker has a queue named "notifications".
  • An AMQP client running in the public cloud. It sends 10 messages to "notifications" and then receives them back.

For the broker, this example uses the Apache ActiveMQ Artemis image from ArtemisCloud.io. The client is a simple Quarkus application.

The example uses two Kubernetes namespaces, "private" and "public", to represent the private data center and public cloud.

Prerequisites

Procedure

  • Clone the repo for this example.
  • Install the Skupper command-line tool
  • Set up your namespaces
  • Deploy the message broker
  • Create your sites
  • Link your sites
  • Expose the message broker
  • Run the client

    1. Clone the repo for this example. Navigate to the appropriate GitHub repository from https://skupper.io/examples/index.html and clone the repository.
    2. Install the Skupper command-line tool

      This example uses the Skupper command-line tool to deploy Skupper. You need to install the skupper command only once for each development environment.

      See the Installation for details about installing the CLI. For configured systems, use the following command:

      sudo dnf install skupper-cli
    3. Set up your namespaces

      Skupper is designed for use with multiple Kubernetes namespaces, usually on different clusters. The skupper and kubectl commands use your kubeconfig and current context to select the namespace where they operate.

      Your kubeconfig is stored in a file in your home directory. The skupper and kubectl commands use the KUBECONFIG environment variable to locate it.

      A single kubeconfig supports only one active context per user. Since you will be using multiple contexts at once in this exercise, you need to create distinct kubeconfigs.

      For each namespace, open a new terminal window. In each terminal, set the KUBECONFIG environment variable to a different path and log in to your cluster. Then create the namespace you wish to use and set the namespace on your current context.

      Note

      The login procedure varies by provider. See the documentation for yours:

      Public:

      export KUBECONFIG=~/.kube/config-public
      # Enter your provider-specific login command
      kubectl create namespace public
      kubectl config set-context --current --namespace public

      Private:

      export KUBECONFIG=~/.kube/config-private
      # Enter your provider-specific login command
      kubectl create namespace private
      kubectl config set-context --current --namespace private
    4. Deploy the message broker

      In Private, use the kubectl apply command to install the broker.

      Private:

      kubectl apply -f server

      Sample output:

      $ kubectl apply -f server
      deployment.apps/broker created
    5. Create your sites

      A Skupper site is a location where components of your application are running. Sites are linked together to form a network for your application. In Kubernetes, a site is associated with a namespace.

      For each namespace, use skupper init to create a site. This deploys the Skupper router and controller. Then use skupper status to see the outcome.

      Public:

      skupper init
      skupper status

      Sample output:

      $ skupper init
      Waiting for LoadBalancer IP or hostname...
      Waiting for status...
      Skupper is now installed in namespace 'public'.  Use 'skupper status' to get more information.
      
      $ skupper status
      Skupper is enabled for namespace "public". It is not connected to any other sites. It has no exposed services.

      Private:

      skupper init
      skupper status

      Sample output:

      $ skupper init
      Waiting for LoadBalancer IP or hostname...
      Waiting for status...
      Skupper is now installed in namespace 'private'.  Use 'skupper status' to get more information.
      
      $ skupper status
      Skupper is enabled for namespace "private". It is not connected to any other sites. It has no exposed services.

      As you move through the steps below, you can use skupper status at any time to check your progress.

    6. Link your sites

      A Skupper link is a channel for communication between two sites. Links serve as a transport for application connections and requests.

      Creating a link requires use of two skupper commands in conjunction, skupper token create and skupper link create.

      The skupper token create command generates a secret token that signifies permission to create a link. The token also carries the link details. Then, in a remote site, The skupper link create command uses the token to create a link to the site that generated it.

      Note

      The link token is truly a secret. Anyone who has the token can link to your site. Make sure that only those you trust have access to it.

      First, use skupper token create in site Public to generate the token. Then, use skupper link create in site Private to link the sites.

      Public:

      skupper token create ~/secret.token

      Sample output:

      $ skupper token create ~/secret.token
      Token written to ~/secret.token

      Private:

      skupper link create ~/secret.token

      Sample output:

      $ skupper link create ~/secret.token
      Site configured to link to https://10.105.193.154:8081/ed9c37f6-d78a-11ec-a8c7-04421a4c5042 (name=link1)
      Check the status of the link using 'skupper link status'.

      If your terminal sessions are on different machines, you may need to use scp or a similar tool to transfer the token securely. By default, tokens expire after a single use or 15 minutes after creation.

    7. Expose the message broker

      In Private, use skupper expose to expose the broker on the Skupper network.

      Then, in Public, use kubectl get service/broker to check that the service appears after a moment.

      Private:

      skupper expose deployment/broker --port 5672

      Sample output:

      $ skupper expose deployment/broker --port 5672
      deployment broker exposed as broker

      Public:

      kubectl get service/broker

      Sample output:

      $ kubectl get service/broker
      NAME     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
      broker   ClusterIP   10.100.58.95   <none>        5672/TCP   2s
    8. Run the client

      In Public, use kubectl run to run the client.

      Public:

      kubectl run client --attach --rm --restart Never --image quay.io/skupper/activemq-example-client --env SERVER=broker

      Sample output:

      $ kubectl run client --attach --rm --restart Never --image quay.io/skupper/activemq-example-client --env SERVER=broker
        ____  __  _____   ___  __ ____  ____
       --/ __ \/ / / / _ | / _ \/ //_/ / / / /
       -/ /_/ / /_/ / __ |/ , / ,< / // /\ \
      --\___\_\____/_/ |_/_/|_/_/|_|\____/_/
      2022-05-27 11:19:07,149 INFO  [io.sma.rea.mes.amqp] (main) SRMSG16201: AMQP broker configured to broker:5672 for channel incoming-messages
      2022-05-27 11:19:07,170 INFO  [io.sma.rea.mes.amqp] (main) SRMSG16201: AMQP broker configured to broker:5672 for channel outgoing-messages
      2022-05-27 11:19:07,198 INFO  [io.sma.rea.mes.amqp] (main) SRMSG16212: Establishing connection with AMQP broker
      2022-05-27 11:19:07,212 INFO  [io.sma.rea.mes.amqp] (main) SRMSG16212: Establishing connection with AMQP broker
      2022-05-27 11:19:07,215 INFO  [io.quarkus] (main) client 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.9.2.Final) started in 0.397s.
      2022-05-27 11:19:07,215 INFO  [io.quarkus] (main) Profile prod activated.
      2022-05-27 11:19:07,215 INFO  [io.quarkus] (main) Installed features: [cdi, smallrye-context-propagation, smallrye-reactive-messaging, smallrye-reactive-messaging-amqp, vertx]
      Sent message 1
      Sent message 2
      Sent message 3
      Sent message 4
      Sent message 5
      Sent message 6
      Sent message 7
      Sent message 8
      Sent message 9
      Sent message 10
      2022-05-27 11:19:07,434 INFO  [io.sma.rea.mes.amqp] (vert.x-eventloop-thread-0) SRMSG16213: Connection with AMQP broker established
      2022-05-27 11:19:07,442 INFO  [io.sma.rea.mes.amqp] (vert.x-eventloop-thread-0) SRMSG16213: Connection with AMQP broker established
      2022-05-27 11:19:07,468 INFO  [io.sma.rea.mes.amqp] (vert.x-eventloop-thread-0) SRMSG16203: AMQP Receiver listening address notifications
      Received message 1
      Received message 2
      Received message 3
      Received message 4
      Received message 5
      Received message 6
      Received message 7
      Received message 8
      Received message 9
      Received message 10
      Result: OK
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.