Skip to main content
Version: 0.0.4

RabbitMQ Consumer Transport

Consume Telegram updates from a RabbitMQ queue.

Add Dependencies

messaging-rabbit-consumer is included in spring-boot-starter, but spring-boot-starter-amqp is not pulled in transitively (it is marked optional to avoid unwanted broker connections when you are using a different transport). You must add it explicitly:

<!-- spring-boot-starter already includes messaging-rabbit-consumer -->
<dependency>
<groupId>uz.osoncode.easygram</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>0.0.3</version>
</dependency>

<!-- Required: provides ConnectionFactory + RabbitTemplate for RABBIT_CONSUMER transport -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

If you are NOT using spring-boot-starter, add messaging-rabbit-consumer directly:

<dependency>
<groupId>uz.osoncode.easygram</groupId>
<artifactId>messaging-rabbit-consumer</artifactId>
<version>0.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

Configuration

application.yml:

easygram:
token: ${BOT_TOKEN}
transport: RABBIT_CONSUMER
rabbit-consumer:
queue: easygram-updates
exchange: easygram-exchange
routing-key: easygram.updates
create-if-absent: true

spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /

Configuration Options

PropertyRequiredDefaultDescription
easygram.rabbit-consumer.queueYesRabbitMQ queue to consume from
easygram.rabbit-consumer.exchangeNoeasygram-exchangeExchange to bind queue to
easygram.rabbit-consumer.routing-keyNoeasygram.updatesRouting key for the binding
easygram.rabbit-consumer.create-if-absentNotrueAuto-create exchange, queue, and binding

Docker Deployment

docker-compose.yml:

version: '3.8'

services:
rabbitmq:
image: rabbitmq:3-management
ports:
- "5672:5672"
- "15672:15672" # Management UI
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest

bot:
build: .
environment:
TELEGRAM_BOT_TRANSPORT: RABBIT_CONSUMER
SPRING_RABBITMQ_HOST: rabbitmq
depends_on:
- rabbitmq
restart: unless-stopped

Example

@BotController
public class RabbitBotHandler {
@BotCommand("/start")
public String onStart() {
return "Bot connected to RabbitMQ!";
}
}

See RabbitMQ Documentation for advanced queue setup.


All transports configured! Next: Advanced Features