The receive operation will not itself be doing this. The client by default prefetches messages (defaults to 1000) for performance, and its likely that is in play here. From prior discussions it seemed Service Bus held its 'message lock' until expiry even when it knews the client/consumer is gone and can never do anything with any messages it hadnt accepted. If you are looking to specifically consume a single message (or a specific number) without prefetching others youd need to disable the prefetching (by configuring it to 0) so that the consumer only gives out a credit for a message to be sent once receive has been called. One issue with that is that if you use a receive call with a timeout the consumer will 'drain' the link if no message has arrived in that timeout, to ensure none was in flight and none can be sent in future (important since prefetch was disabled), and historically ServiceBus didnt support this so the attempt would timeout and the client would then close the consumer. If thats still the case, you would only be able to use a prefetch of 1, leaving a single message potentially in the same situation as before.
Robbie On 24 May 2018 at 10:30, Abhishek Kumar <[email protected]> wrote: > Hi Team, > > we are having issue isse with recive functionality. > > Scenario - There are 10 message available in ServiceBus Queue. > > Step 1 - Received only one message and acknowledged successfully. > > ISSUE - One message removed immediately and remaining 9 message moved > into *dead > letter queue* after elapsing lock duration. "Max delivery count" is 1 for > queue. > > Reason - When i performed *receive() *operation, message delivery count > increasing for all message. As i know, receive operation can receive only > message. > > I don't know why "receive()" operation increasing delivery count to all > message instead of 1. > > Could you please suggest your opinion for resolving this issue. > > Please find below code snippet. I am using "qpid-jms-client - 0.32.0". > > > //Code Snippet > > package com.test; > > import java.util.Hashtable; > > import javax.jms.Connection; > import javax.jms.ConnectionFactory; > import javax.jms.Destination; > import javax.jms.Message; > import javax.jms.MessageConsumer; > import javax.jms.Queue; > import javax.jms.Session; > import javax.naming.Context; > import javax.naming.InitialContext; > > public class TestReceive { > > public static void main(String[] args) throws Exception { > Destination destination = null; > > // set up JNDI context > Hashtable<String, String> hashtable = new Hashtable<>(); > > hashtable.put("connectionfactory.SBCF", "failover:(amqps://" + " > XXXXX.servicebus.windows.net" + > ")?failover.reconnectDelay=2000&failover.maxReconnectAttempts=-1&jms.forceAsyncSend=true&amqp.idleTimeout=180000&transport.connectTimeout=180"); > > hashtable.put("queue.QUEUE", "qName"); > > hashtable.put(Context.INITIAL_CONTEXT_FACTORY, > "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); > > Context context = new InitialContext(hashtable); > ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF"); > > destination = (Destination) context.lookup("QUEUE"); > > // Create Connection > Connection connection = cf.createConnection("****Username****", > "************password**********"); > connection.setExceptionListener(new ConnectionExceptionListener()); > > Session session = connection.createSession(false, > Session.CLIENT_ACKNOWLEDGE); > Queue queue = (Queue) context.lookup("QUEUE"); > > > MessageConsumer messageConsumer = session.createConsumer(queue); > > > connection.start(); > System.out.println("*** Connection Start ****"); > > Message message = messageConsumer.receive(1000); > > long jmsTimestamp = message.getJMSTimestamp(); > > System.out.println("jmsTimestamp :: " + jmsTimestamp); > > message.acknowledge(); > > System.out.println("**** END ***"); > connection.close(); > > context.close(); > } > > } > > > Regards, > Abhishek Kumar --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
