title: Move a message to subscription deadletter for failed HTTP request
body: <p>I've been looking for resources but I can't seem to find what I need.. I have an Azure function with a Service Bus trigger. From this, I make an HTTP call with one of the values found in the Service Bus message.</p>
  <p>An additional requirement for me is to deadletter a message if it the HTTP call fails. But as I understand it, the message is not present in the subscription anymore because it was properly received. Is there a way for me to keep the message in the subscription, and then dispose it once it is successful (transfer to DLQ if not?)</p>
  <p>I found this piece of code but I'm not sure how it's sending to the DLQ?
  <a href="https://github.com/Azure/azure-sdk-for-python/blob/azure-servicebus_7.3.0/sdk/servicebus/azure-servicebus/samples/sync_samples/receive_deadlettered_messages.py" rel="nofollow noreferrer">https://github.com/Azure/azure-sdk-for-python/blob/azure-servicebus_7.3.0/sdk/servicebus/azure-servicebus/samples/sync_samples/receive_deadlettered_messages.py</a></p>
  <pre><code>&quot;&quot;&quot;
  Example to show receiving dead-lettered messages from a Service Bus Queue.
  &quot;&quot;&quot;
  
  # pylint: disable=C0111
  
  import os
  from azure.servicebus import ServiceBusClient, ServiceBusMessage, ServiceBusSubQueue
  
  CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
  QUEUE_NAME = os.environ[&quot;SERVICE_BUS_QUEUE_NAME&quot;]
  
  servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR)
  
  with servicebus_client:
      sender = servicebus_client.get_queue_sender(queue_name=QUEUE_NAME)
      messages = [ServiceBusMessage(&quot;Message to be deadlettered&quot;) for _ in range(10)]
      with sender:
          sender.send_messages(messages)
  
      print('dead lettering messages')
      receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)
      with receiver:
          received_msgs = receiver.receive_messages(max_message_count=10, max_wait_time=5)
          for msg in received_msgs:
              print(str(msg))
              receiver.dead_letter_message(msg)
  
      print('receiving deadlettered messages')
      dlq_receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, sub_queue=ServiceBusSubQueue.DEAD_LETTER)
      with dlq_receiver:
          received_msgs = dlq_receiver.receive_messages(max_message_count=10, max_wait_time=5)
          for msg in received_msgs:
              print(str(msg))
              dlq_receiver.complete_message(msg)
  
  print(&quot;Receive is done.&quot;)
  </code></pre>
  <p>Here is a code snippet in mine:</p>
  <pre><code>async def main(msg: func.ServiceBusMessage):
      try:
          logging.info('Python ServiceBus queue trigger processed message: %s',
          msg.get_body().decode('utf-8'))
          await asyncio.gather(wait(), wait())
  
          result = json.dumps({
              'message_id': msg.message_id,
              'metadata' : msg.metadata
          })
  
          msgobj = json.loads(result)
  
          val = msgobj['metadata']['value']
          run_pipeline(val, msg)
      except Exception as e:
          logging.error(f&quot;trigger failed: {e}&quot;)
  </code></pre>
  <p>TLDR; How do I keep the message in the subscription and either dispose them (if successful) or send them to the DLQ if not?</p>