title: Failed to create RabbitMQ queue
body: <p>I received a suggestion on <a href="https://stackoverflow.com/questions/59363167/handling-dead-letter-queue-with-delay/59364434#comment104940914_59364434">this question</a>, on a comment, saying that I might not have the Exchange I needed because my queues already existed. So, I manually deleted them all.</p>
  
  <p>However, when re-deploying the application, I had the following exception for all the queues I had:</p>
  
  <pre class="lang-java prettyprint-override"><code>org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[myInput.group]
      at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:721)
      at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:598)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1472)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: java.io.IOException
      at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105)
      at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101)
      at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123)
      at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992)
      at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.queueDeclarePassive(AutorecoveringChannel.java:364)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:980)
      at com.sun.proxy.$Proxy166.queueDeclarePassive(Unknown Source)
      at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:700)
      ... 3 more
  Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=404, reply-text=NOT_FOUND - no queue 'myInput.group' in vhost 'production', class-id=50, method-id=10)
      at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
      at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32)
      at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366)
      at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229)
      at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117)
      ... 12 more
  Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method&lt;channel.close&gt;(reply-code=404, reply-text=NOT_FOUND - no queue 'myInput.group' in vhost 'production', class-id=50, method-id=10)
      at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505)
      at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336)
      at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143)
      at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90)
      at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634)
      at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47)
      at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572)
      ... 1 more
  </code></pre>
  
  <p>I'm not sure what this means, since I obviously want to create the queue <code>myInput.group</code>, and it seems to be complaining it does not exists...</p>
  
  <p>I've also checked on <a href="https://stackoverflow.com/questions/49334193/rabbitmq-failed-to-declare-queue-and-listener-is-not-able-to-get-queue-on-server">this question</a> that my problem could be permissions. But I should have them - otherwise I believe I wouldn't be able to delete the queues...</p>
  
  <p>Can you guide me to a solution?</p>
  
  <hr>
  
  <p>The code from my previous question, to help you with the investigation:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class HandlerDlq {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(HandlerDlq.class);
      private static final String X_RETRIES_HEADER = "x-retries";
      private static final String X_DELAY_HEADER = "x-delay";
      private static final int NUMBER_OF_RETRIES = 3;
      private static final int DELAY_MS = 300000;
      private RabbitTemplate rabbitTemplate;
  
      @Autowired
      public HandlerDlq(RabbitTemplate rabbitTemplate) {
          this.rabbitTemplate = rabbitTemplate;
      }
  
      @RabbitListener(queues = MessageInputProcessor.DLQ)
      public void rePublish(Message failedMessage) {
          Map&lt;String, Object&gt; headers = failedMessage.getMessageProperties().getHeaders();
          Integer  retriesHeader = (Integer) headers.get(X_RETRIES_HEADER);
          if (retriesHeader == null) {
              retriesHeader = 0;
          }
          if (retriesHeader &gt; NUMBER_OF_RETRIES) {
              LOGGER.warn("Message {} added to failed messages queue", failedMessage);
              this.rabbitTemplate.send(MessageInputProcessor.FAILED, failedMessage);
              throw new ImmediateAcknowledgeAmqpException("Message failed after " + NUMBER_OF_RETRIES + " attempts");
          }
          retriesHeader++;
          headers.put(X_RETRIES_HEADER, retriesHeader);
          headers.put(X_DELAY_HEADER, DELAY_MS * retriesHeader);
          LOGGER.warn("Retrying message, {} attempts", retriesHeader);
          this.rabbitTemplate.send(MessageInputProcessor.DELAY_EXCHANGE, MessageInputProcessor.INPUT_DESTINATION, failedMessage);
      }
  
      @Bean
      public DirectExchange delayExchange() {
          DirectExchange exchange = new DirectExchange(MessageInputProcessor.DELAY_EXCHANGE);
          exchange.setDelayed(true);
          return exchange;
      }
  
      @Bean
      public Binding bindOriginalToDelay() {
          return BindingBuilder.bind(new Queue(MessageInputProcessor.INPUT_DESTINATION)).to(delayExchange()).with(MessageInputProcessor.INPUT_DESTINATION);
      }
  
      @Bean
      public Queue parkingLot() {
          return new Queue(MessageInputProcessor.FAILED);
      }
  }
  </code></pre>
  
  <p>My <code>MessageInputProcessor</code> interface:</p>
  
  <pre class="lang-java prettyprint-override"><code>public interface MessageInputProcessor {
  
      String INPUT = "myInput";
  
      String INPUT_DESTINATION = "myInput.group";
  
      String DLQ = INPUT_DESTINATION + ".dlq"; //from application.properties file
  
      String FAILED = INPUT + "-failed";
  
      String DELAY_EXCHANGE = INPUT_DESTINATION + "-DlqReRouter";
  
      @Input
      SubscribableChannel storageManagerInput();
  
      @Input(MessageInputProcessor.FAILED)
      SubscribableChannel storageManagerFailed();
  }
  </code></pre>
  
  <p>And my properties file:</p>
  
  <pre><code>#dlx/dlq setup - retry dead letter 5 minutes later (300000ms later)
  spring.cloud.stream.rabbit.bindings.myInput.consumer.auto-bind-dlq=true
  spring.cloud.stream.rabbit.bindings.myInput.consumer.republish-to-dlq=true
  spring.cloud.stream.rabbit.bindings.myInput.consumer.dlq-ttl=3000
  
  #input
  spring.cloud.stream.bindings.myInput.destination=myInput
  spring.cloud.stream.bindings.myInput.group=group
  </code></pre>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>I do have <code>EnableBinding</code> annotation in another component on the project (and now I've tried to add to the class HandlerDlq, but the error was the same), and I have the log entry:</p>
  
  <blockquote>
    <p>2019-12-17 08:45:11.584 INFO 96124 --- [ main] c.s.b.r.p.RabbitExchangeQueueProvisioner : declaring queue for inbound: myInput.group, bound to: myInput</p>
  </blockquote>
  
  <p>After that, there is an error message without stacktrace. Content below:</p>
  
  <pre><code>{ "written_at":"2019-12-17T14:06:59.263Z","written_ts":460692906701698,"type":"log","logger":"org.springframework.amqp.rabbit.connection.CachingConnectionFactory","thread":"AMQP Connection &lt;ip&gt;:5672","level":"ERROR","categories":[],"msg":"Channel shutdown: connection error; protocol method: #method&lt;connection.close&gt;(reply-code=503, reply-text=COMMAND_INVALID - unknown exchange type 'x-delayed-message', class-id=40, method-id=10)","tenant_id":"-","component_type":"application","component_id":"******","space_name":"dev","component_name":"*******","component_instance":"0","organization_id":"****","correlation_id":"-","organization_name":"****","space_id":"*****","container_id":"***","custom_fields":{} }
  </code></pre>