Git Product home page Git Product logo

ivangfr / springboot-activemq-rabbitmq-delayed-messages Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 4.0 1.58 MB

The goal of this project is to create an application that produces and consumes delayed messages randomly. Those messages are sent to ActiveMQ or RabbitMQ. The delayed broker to which the message is sent depends on a feature toggle defined in Unleash.

Java 70.04% Shell 27.34% Dockerfile 2.63%
activemq spring-boot rabbitmq unleash docker java jib spring-cloud-stream spring-activemq spring-amqp

springboot-activemq-rabbitmq-delayed-messages's Introduction

springboot-activemq-rabbitmq-delayed-messages

The goal of this project is to create an application that produces and consumes delayed messages randomly. Those messages are sent to ActiveMQ or RabbitMQ. The delayed broker to which the message is sent depends on a feature toggle defined in Unleash.

Proof-of-Concepts & Articles

On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.

Project diagram

project-diagram

Applications

delayed-message-producer-consumer is a Spring Boot Java application that produces and consumes messages with random delays.

These delayed messages are sent to ActiveMQ or RabbitMQ brokers.

However, both brokers are not ready to handle delayed messages by default. For it, we needed to enable the scheduler in ActiveMQ and, in RabbitMQ, we install the Delayed Message Plugin.

Furthermore, in order to easily switch the delayed message broker to where the messages are sent without restarting the application, we use a feature toggle called rabbitMQEnabled that is defined in Unleash.

Prerequisites

Initialize Environment

Open a terminal and inside springboot-activemq-rabbitmq-delayed-messages root folder run

./init-environment.sh

Note: this script, besides starting ActiveMQ, RabbitMQ, Unleash and Postgres, it will create in Unleash a feature toggle called rabbitMQEnabled.

Running application with Maven

  • In a terminal, make sure you are inside springboot-activemq-rabbitmq-delayed-messages folder
  • Run the following command
    ./mvnw clean spring-boot:run --projects delayed-message-producer-consumer \
      -Dspring-boot.run.jvmArguments="-Dunleash.api.key='*:development.some-random-string'"
    

    Note: the UNLEASH_API_KEY was created during the step Initialize Environment

Running application as Docker container

  • Build Docker image

    • In a terminal, make sure you are inside springboot-activemq-rabbitmq-delayed-messages root folder
    • Run the following script
      ./docker-build.sh
      
  • Environment variables

Environment Variable Description
ACTIVEMQ_BROKER_URL Specify URL of the ActiveMQ broker to use (default tcp://localhost:61616)
ACTIVEMQ_USER Specify user of the ActiveMQ broker (default admin)
ACTIVEMQ_PASSWORD Specify password of the ActiveMQ broker (default admin)
RABBITMQ_ADDRESSES Specify addresses of the RabbitMQ broker to use (default localhost:5672)
RABBITMQ_USER Specify user of the RabbitMQ broker (default admin)
RABBITMQ_PASSWORD Specify password of the RabbitMQ broker (default admin)
UNLEASH_API_URL Specify URL of the Unleash to use (default http://localhost:4242/api)
UNLEASH_API_KEY Specify API key of the Unleash to use (default change-me)
MESSAGES_PER_SECOND Specify the number of messages per second to be produced (default 1)
PRODUCER_RUNNER_ENABLED Specify if producer runner is enabled to produce messages (default true)
PRODUCER_LOGGING_ENABLED Specify if producer logging is enabled (default false)
CONSUMER_LOGGING_ENABLED Specify if consumer logging is enabled (default true)
  • Start Docker container

    • In a terminal, run the following command

      docker run --rm --name delayed-message-producer-consumer \
        -e ACTIVEMQ_BROKER_URL=tcp://activemq:61616 \
        -e RABBITMQ_ADDRESSES=rabbitmq:5672 \
        -e UNLEASH_API_URL=http://unleash:4242/api \
        -e UNLEASH_API_KEY='*:development.some-random-string' \
        --network=springboot-activemq-rabbitmq-delayed-messages_default \
        ivanfranchin/delayed-message-producer-consumer:1.0.0
      

      Note: the UNLEASH_API_KEY was created during the step Initialize Environment

    • [Optional] To start a 2nd Docker container, in another terminal, run the command below

      docker run --rm --name delayed-message-producer-consumer-2 \
        -e ACTIVEMQ_BROKER_URL=tcp://activemq:61616 \
        -e RABBITMQ_ADDRESSES=rabbitmq:5672 \
        -e UNLEASH_API_URL=http://unleash:4242/api \
        -e UNLEASH_API_KEY='*:development.some-random-string' \
        --network=springboot-activemq-rabbitmq-delayed-messages_default \
        ivanfranchin/delayed-message-producer-consumer:1.0.0
      

Switching Delayed Message Brokers

  • Access Unleash website at http://localhost:4242
  • To login, type admin and unleash4all for username and password, respectively;
  • In Projects page, select Default;
  • You should see the rabbitMQEnabled feature toggle; unleash-rabbitmqenabled
  • The API token provided to delayed-messages-producer-consumer, was created to development environment. So, if the development checkbox is enabled, the messages will be sent to RabbitMQ; otherwise, they will go to ActiveMQ.

Useful links

  • ActiveMQ

    • Access http://localhost:8161
    • Click Manage ActiveMQ broker
    • To login, type admin for both username and password
  • RabbitMQ

  • Unleash

    • Access http://localhost:4242
    • To login, type admin and unleash4all for username and password, respectively

Shutdown

  • To stop delayed-message-producer-consumer application, go to the terminal where it is running and press Ctrl+C
  • To stop and remove docker-compose containers, network and volumes, go to a terminal and, inside springboot-activemq-rabbitmq-delayed-messages root folder, run the following command
    ./shutdown-environment.sh
    

Cleanup

To remove the Docker image create by this project, go to a terminal and, inside springboot-activemq-rabbitmq-delayed-messages root folder, run the following script

./remove-docker-images.sh

springboot-activemq-rabbitmq-delayed-messages's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.