/delayed-queue

RabbitMQ task queue go sdk

Primary LanguageGoMIT LicenseMIT

delayed-queue-go-sdk

A delayed queue base rabbitmq, use the rabbitmq_delayed_message_exchange's plugin.

We also handle a disconnection and reconnection of rabbitmq trying every 5 sec if a new connection is available.

Installation

Start up rabbitmq in local.

docker compose up -d

Usage

Publish Message

You can publish the message by calling publish()

	publisher, err := queue.NewPublisher(
		"amqp://admin:password@localhost:5672/",
		queue.WithPublisherOptionsExchange("test"),
		queue.WithPublisherOptionsQueue("test"),
		queue.WithPublisherOptionsKey("test"),
	)
	if err != nil {
		fmt.Printf("%+v", err)
	}

	defer publisher.Disconnect()

	err = publisher.Publish([]byte("Hello"), 3*time.Second)
	if err != nil {
		fmt.Printf("%+v", err)
	}

Subscribe Message

comsumer, err := queue.NewComsumer(
		"amqp://admin:password@localhost:5672/",
		queue.WithComsumerOptionsExchange("test"),
		queue.WithComsumerOptionsQueue("test"),
		queue.WithComsumerOptionsKey("test"),
	)
	if err != nil {
		fmt.Printf("%+v", err)
	}

	defer comsumer.Disconnect()

	deliveries := comsumer.Consume()

	for d := range deliveries {
		log.Printf("Received a message: %s", d.Body)
	}

Questions & Suggestions

Please open an issue here.

License

MIT