Skip to content

Channel is closed after Channel.ExchangeDeclarePassive fails #242

@ldelossa

Description

@ldelossa

Hello,

I'm trying to determine if an Exchange is declared on rabbitmq, and if not declare it and bind. I have the following code:

note* rc = amqp client.

// Determine if Exchange exists
	err = rc.Channel.ExchangeDeclarePassive(rc.rabbitConfigCtx.Exchange,
		"topic", true, false, false, false, nil)

	fmt.Println(err)

	// Create Exchange if Exchange does not exist
	if err != nil {
		log.Lprintf(log.LevelInfo, "RabbitMQDeliverer: Supplied exchange is not declared, declaring...")

		// Declare Exchange
		err = rc.Channel.ExchangeDeclare(rc.rabbitConfigCtx.Exchange, "topic", true, false, false, false, nil)
		if err != nil {
			log.Lprintf(log.LevelWarning, "Could not declare exchange %s: %s", rc.rabbitConfigCtx.Exchange, err)
			return err
		}

		// Bind Queue to Exchange
		err = rc.Channel.QueueBind(rc.rabbitConfigCtx.Queue, "*.*", rc.rabbitConfigCtx.Exchange,
			false, nil)
		if err != nil {
			log.Lprintf(log.LevelWarning, "Could not bind queue: %s to exchange %s",
				rc.rabbitConfigCtx.Queue, rc.rabbitConfigCtx.Exchange)
			return err
		}
	}

However, I get this error message:

2017-02-13T22:40:17.856Z [level=INFO] RabbitMQDeliverer: Supplied exchange is not declared, declaring...
2017-02-13T22:40:17.857Z [level=WARNING] Could not declare exchange player-logs: Exception (504) Reason: "channel/connection is not open"
2017-02-13T22:40:17.857Z [level=WARNING] RabbitMQDeliverer unable to start processing: Exception (504) Reason: "channel/connection is not open"

If I place a Dial() attempt right before the call to ExchangeDeclare() everything works fine.

Would a failure to ExchangeDeclarePassive() cause the channel to be closed? If so is it normal to have to re-establish this channel ?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions