title: How to fetch messages from an Azure Service Bus Queue in "PeekLock" mode using AMQP?
body: <p>We're trying to consume Azure Service Bus in a Node application. <strong>Our requirement is to fetch multiple messages from a queue</strong>. </p>
  
  <p>Since Azure SDK for Node doesn't support batch retrieval, we decided to use AMQP. While we're able to fetch messages using Peek Messages as described here (<a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-request-response#message-operations" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-request-response#message-operations</a>). </p>
  
  <p>What we are noticing is that as soon as messages are fetched, they are getting removed from the queue. I am wondering if anyone has an insight into how we can fetch messages in "PeekLock" mode using AMQP and Node. For AMQP, we're using amqp10 node package (<a href="https://www.npmjs.com/package/amqp10" rel="nofollow noreferrer">https://www.npmjs.com/package/amqp10</a>).</p>
  
  <p>Here's our code for peeking at the messages:</p>
  
  <pre><code>const AMQPClient = require('amqp10/lib').Client,
  Policy = require('amqp10/lib').Policy;
  
  const protocol = 'amqps';
  const keyName = 'RootManageSharedAccessKey';
  const sasKey = 'My Shared Access Key'
  const serviceBusHost = 'account-name.servicebus.windows.net';
  const uri = protocol + '://' + encodeURIComponent(keyName) + ':' + encodeURIComponent(sasKey) + '@' + serviceBusHost;
  const queueName = 'test1';
  var client = new AMQPClient(Policy.ServiceBusQueue);
  client.connect(uri)
  .then(function () {
      return Promise.all([
          client.createReceiver(queueName),
          client.createSender(queueName)
      ]);
  })
  .spread(function(receiver, sender) {
      console.log(receiver);
      console.log(sender);
      console.log('--------------------------------------------------------------------------');
      receiver.on('errorReceived', function(err) {
          // check for errors
          console.log(err);
      });
      receiver.on('message', function(message) {
          console.log('Received message');
          console.log(message);
          console.log('------------------------------------');
      });
  
      return sender.send([], {
          operation: 'com.microsoft:peek-message',
          'message-count': 5
      });
  })
  .error(function (e) {
      console.warn('connection error: ', e);
  });
  </code></pre>