使用Java API从Azure Queue读取消息失败,并且它们将进入死信队列

问题描述:

当我尝试使用Java API从Azure Queue读取消息时 - 他们将进入死信队列..我使用了以下程序

When i try to read messages from Azure Queue using Java API - They are going to Dead Letter queue..I have used below program

公共类ReceiveMessage {
$


 静态最终Gson GSON = new Gson();



    //命名空间的连接字符串可以从Azure门户网站获得,价格为
    //'共享访问政策'部分。

    private static final String connectionString =" Endpoint";

    private static final String queueName =" test queue&quot ;;

//





public static void main(String [] args) 

{

System.out.println("Hello World!");

尝试{

run();

} catch(exception ex){

System.out .println("主要方法中的例外 " + ex.getMessage());

}

}



public static void run()throws Exception {



QueueClient receiveClient = new QueueClient(new ConnectionStringBuilder(connectionString,queueName),ReceiveMode.RECEIVEANDDELETE);

        registerReceiver(receiveClient);

$


$
        //关闭接收器以关闭接收循环

        receiveClient.close();

    }
static void  registerReceiver(QueueClient queueClient)抛出异常{

        //注册RegisterMessageHandler回调

        queueClient.registerMessageHandler(new IMessageHandler(){

//当消息处理程序循环获取消息时调用的回调





      公共CompletableFuture<空隙率> onMessageAsync(即时聊天消息){



    &NBSP ;          byte [] body = message.getBody();   



              的System.out.println(QUOT; message.getMessageId()=== " + message.getMessageId());
$
               System.out.println( " message.getSequenceNumber()=== " + message.getSequenceNumber());

&nb SP;                           System.out.println(" message.getEnqueuedTimeUtc()=== " + message.getEnqueuedTimeUtc());

                            System.out.println(" message.getExpiresAtUtc()=== " + message.getExpiresAtUtc());

                            System.out.println(" message.getContentType()=== " + message.getContentType());
$


                            System.out.println(" body.toString()   === " + body.toString());
$




                    return CompletableFuture.completedFuture(null);

        }


                //当消息处理程序有异常报告时调用回调

                public void notifyException(Throwable throwable,ExceptionPhase exceptionPhase){

        System.out.printf(exceptionPhase +" - " + throwable.getMessage());

        }¥b $ b        },b
    // 1个并发通话,消息自动完成,自动续订时间为
       新的MessageHandlerOptions(1,true,Duration.ofMinutes(1)));

    }

Public class ReceiveMessage {

 static final Gson GSON = new Gson();

   // Connection String for the namespace can be obtained from the Azure portal under the
   // 'Shared Access policies' section.
   private static final String connectionString = "Endpoint";
   private static final String queueName = "test queue";
//


public static void main(String[] args) 
{
System.out.println("Hello World!");
try {
run();
}catch(Exception ex){
System.out.println("Exception in Main Method  "+ex.getMessage());
}
}

public static void run() throws Exception {

QueueClient receiveClient = new QueueClient(new ConnectionStringBuilder(connectionString, queueName), ReceiveMode.RECEIVEANDDELETE);
        registerReceiver(receiveClient);



        // shut down receiver to close the receive loop
        receiveClient.close();
    }
static void  registerReceiver(QueueClient queueClient) throws Exception {
        // register the RegisterMessageHandler callback
        queueClient.registerMessageHandler(new IMessageHandler() {
// callback invoked when the message handler loop has obtained a message


            public CompletableFuture<Void> onMessageAsync(IMessage message) {

                            byte[] body = message.getBody();    

                            System.out.println(" message.getMessageId()===  "+message.getMessageId());
                            System.out.println(" message.getSequenceNumber()===  "+message.getSequenceNumber());
                            System.out.println(" message.getEnqueuedTimeUtc()===  "+message.getEnqueuedTimeUtc());
                            System.out.println(" message.getExpiresAtUtc()===  "+message.getExpiresAtUtc());
                            System.out.println(" message.getContentType()===  "+message.getContentType());

                            System.out.println(" body.toString()   ===  "+body.toString());


                    return CompletableFuture.completedFuture(null);
        }

                // callback invoked when the message handler has an exception to report
                public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
        System.out.printf(exceptionPhase + "-" + throwable.getMessage());
        }
        },
    // 1 concurrent call, messages are auto-completed, auto-renew duration
        new MessageHandlerOptions(1, true, Duration.ofMinutes(1)));
    }

感谢任何帮助......

Any help is appreciated...

谢谢,

Sreeman。



您好  Sreemannarayana,

Hello Sreemannarayana,

您能否告诉我们您所关注的文件?

Can you let us know the documentation you are following?

谢谢!