MCPcopy Create free account
hub / github.com/codealong-dev/ride-sharing / declareAndBindQueue

Method declareAndBindQueue

shared/messaging/rabbitmq.go:281–312  ·  view source on GitHub ↗
(queueName string, messageTypes []string, exchange string)

Source from the content-addressed store, hash-verified

279}
280
281func (r *RabbitMQ) declareAndBindQueue(queueName string, messageTypes []string, exchange string) error {
282 // Add dead letter configuration
283 args := amqp.Table{
284 "x-dead-letter-exchange": DeadLetterExchange,
285 }
286
287 q, err := r.Channel.QueueDeclare(
288 queueName, // name
289 true, // durable
290 false, // delete when unused
291 false, // exclusive
292 false, // no-wait
293 args, // arguments with DLX config
294 )
295 if err != nil {
296 log.Fatal(err)
297 }
298
299 for _, msg := range messageTypes {
300 if err := r.Channel.QueueBind(
301 q.Name, // queue name
302 msg, // routing key
303 exchange, // exchange
304 false,
305 nil,
306 ); err != nil {
307 return fmt.Errorf("failed to bind queue to %s: %v", queueName, err)
308 }
309 }
310
311 return nil
312}
313
314func (r *RabbitMQ) Close() {
315 if r.conn != nil {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected