使用Java API从Azure Queue读取消息失败,并且它们将进入死信队列 [英] Read messages from Azure Queue using Java API is failing and they are going to Dead Letter queue

查看:62
本文介绍了使用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" ;;

//





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(){

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





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



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



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

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

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

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


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




  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return CompletableFuture.completedFuture(null);

  &NBSP; &NBSP; &NBSP; }


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

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public void notifyException(Throwable throwable,ExceptionPhase exceptionPhase){

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

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

  &NBSP; }

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?

谢谢!


这篇关于使用Java API从Azure Queue读取消息失败,并且它们将进入死信队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆