BroadwayRabbitMQ

repository·main·Indexed 42 days ago

https://github.com/elixir-broadway/broadway_rabbitmq

A RabbitMQ connector for the Broadway pipeline processing library that allows developers to use RabbitMQ as a message source (producer) within an Elixir Broadway pipeline.

Tokens
556
Snippets
4
Records
4
Agent score
2%

What's inside BroadwayRabbitMQ

  1. Run RabbitMQ via Docker Compose

    main

    You can use the provided docker-compose.yml to spin up a RabbitMQ instance for local development or testing. This configuration uses the rabbitmq:3.11.9-alpine image and exposes the standard AMQP port 5672 to your host machine.

    services:
      rabbitmq:
        image: "rabbitmq:3.11.9-alpine"
        ports:
          - "5672:5672"
  2. Configure a BroadwayRabbitMQ Producer

    main

    To consume messages from RabbitMQ, configure a producer in your Broadway pipeline using BroadwayRabbitMQ.Producer. You must specify the queue name in the producer options. The concurrency option controls how many processes are started to consume from the queue.

    defmodule MyBroadway do
      use Broadway
    
      def start_link(_opts) do
        Broadway.start_link(__MODULE__,
          name: __MODULE__,
          producer: [
            module: {BroadwayRabbitMQ.Producer,
              queue: "my_queue",
            },
            concurrency: 1
          ],
          processors: [
            default: [
              concurrency: 10
            ]
          ]
        )
      end
    
      def handle_message(_, message, _) do
        IO.inspect(message.data, label: "Got message")
        message
      end
    end