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

Function NewRabbitMQ

shared/messaging/rabbitmq.go:25–49  ·  view source on GitHub ↗
(uri string)

Source from the content-addressed store, hash-verified

23}
24
25func NewRabbitMQ(uri string) (*RabbitMQ, error) {
26 conn, err := amqp.Dial(uri)
27 if err != nil {
28 return nil, fmt.Errorf("failed to connect to RabbitMQ: %v", err)
29 }
30
31 ch, err := conn.Channel()
32 if err != nil {
33 conn.Close()
34 return nil, fmt.Errorf("failed to create channel: %v", err)
35 }
36
37 rmq := &RabbitMQ{
38 conn: conn,
39 Channel: ch,
40 }
41
42 if err := rmq.setupExchangesAndQueues(); err != nil {
43 // Clean up if setup fails
44 rmq.Close()
45 return nil, fmt.Errorf("failed to setup exchanges and queues: %v", err)
46 }
47
48 return rmq, nil
49}
50
51type MessageHandler func(context.Context, amqp.Delivery) error
52

Callers 4

mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92

Calls 2

CloseMethod · 0.95

Tested by

no test coverage detected