gpt4 book ai didi

azure - 如何使用 JMS 将计划消息发送到 Azure 服务总线

转载 作者:行者123 更新时间:2023-12-03 00:43:00 26 4
gpt4 key购买 nike

Azure 服务总线能够发送计划消息。使用此处描述的 AMQP 协议(protocol)发送计划消息:https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-request-response#message-operations

Schedules messages.Request

The request message must include the following application properties:

| Key | Value | Type | Required | Value Contents

| operation | string | Yes | com.microsoft:schedule-message

| com.microsoft:server-timeout | uint | No | Operation server timeout in milliseconds.|

我使用 Azure 服务总线和 Spring Framework 中的 java JmsTemplate。如何映射消息头来发送预定消息?

    @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;
}
});
}

-产生序号消息

最佳答案

此代码有效:

Azure SB 使用未记录的消息注释 header 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;
}
});
}

关于azure - 如何使用 JMS 将计划消息发送到 Azure 服务总线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45631740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com