2017-08-11 120 views
0

Azure服务总线能够发送预定消息。 用此处描述的AMQP协议发送计划消息:https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-request-response#message-operations如何使用JMS将预定消息发送到Azure服务总线

计划消息。 请求

该请求消息必须包括以下应用程序属性:

| Key |值|类型|必需|价值内容

|操作|字符串|是| com.microsoft:schedule-message

| com.microsoft:server-timeout | uint |没有|操作服务器超时(以毫秒为单位)

我使用Spring Framework的java JmsTemplate与Azure服务总线一起工作。 地图信息标题如何发送预定的信息?

@Test 
public void sendMessageWithHeaders() { 


    jmsTemplate.send("test-topic-2", new MessageCreator() { 
     @Override 
     public Message createMessage(Session session) throws JMSException { 
      TextMessage textMessage = session.createTextMessage("test-123"); 
      ((JmsTextMessage) textMessage).setValidatePropertyNames(false); 
      textMessage.setStringProperty("operation", "com.microsoft:schedule-message"); 

      textMessage.setIntProperty("com.microsoft:server-timeout", 100000); 
      return textMessage; 
     } 
    }); 
} 

-produce序消息

回答

1

此代码工作:

天青SB使用未记录的消息注释头x-opt-scheduled-enqueue-time

static final long ONE_MINUTE_IN_MILLIS=60000;//millisecs 

@Test 
public void sendMessageWithHeaders() { 


    jmsTemplate.send(queueName, new MessageCreator() { 
     @Override 
     public Message createMessage(Session session) throws JMSException { 
      TextMessage textMessage = session.createTextMessage("test-123"); 
      ((JmsTextMessage) textMessage).setValidatePropertyNames(false); 

      org.apache.qpid.proton.message.Message amqpMessage = ((AmqpJmsTextMessageFacade)((JmsTextMessage)textMessage).getFacade()).getAmqpMessage(); 
      HashMap applicationPropertiesMap = new HashMap(); 
      applicationPropertiesMap.put("operation", "com.microsoft:schedule-message"); 
      applicationPropertiesMap.put("com.microsoft:server-timeout", 100000000); 
      amqpMessage.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap)); 

      Calendar date = Calendar.getInstance(); 
      long t= date.getTimeInMillis(); 
      Date afterAddingTenMins=new Date(t + (10 * ONE_MINUTE_IN_MILLIS)); 

      amqpMessage.getMessageAnnotations().getValue().put(Symbol.valueOf("x-opt-scheduled-enqueue-time"), afterAddingTenMins); 

      return textMessage; 
     } 
    }); 
} 
相关问题