You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向Premium层Azure Service Bus发送会话消息失败问题求助

Azure Service Bus Premium层会话队列发送消息报错问题

我使用com.azure.spring:spring-cloud-azure-starter-servicebus-jms:4.7.0结合Spring JmsTemplate(Spring Boot版本2.6.8)向Azure Service Bus队列发送消息。根据文档,发送到启用会话的队列需设置消息的JMSXGroupID属性。

该操作在标准层Service Bus队列上完全正常,但应用于Premium层Service Bus时出现如下错误:

Caused by: org.apache.qpid.jms.provider.ProviderException: The SessionId was not set on a message, and it cannot be sent to the entity. Entities that have session support enabled can only receive messages that have the SessionId set to a valid value. Reference:b555fb0f-abef-4c8e-a1e3-16f3040ef2a0, TrackingId:ae38db690000043a00056bc2647dfc26_G5S1_B22S1, SystemTracker:queuenamehere, Timestamp:2023-06-05T15:15:50 [condition = amqp:not-allowed] at org.apache.qpid.jms.provider.amqp.AmqpSupport.convertToNonFatalException(AmqpSupport.java:181) ~[qpid-jms-client-0.53.0.jar:na] at org.apache.qpid.jms.provider.amqp.AmqpFixedProducer.applyDeliveryStateUpdate(AmqpFixedProducer.java:252) ~[qpid-jms-client-0.53.0.jar:na] at org.apache.qpid.jms.provider.amqp.AmqpFixedProducer.processDeliveryUpdates(AmqpFixedProducer.java:223) ~[qpid-jms-client-0.53.0.jar:na]

队列及Service Bus资源均通过Terraform脚本创建,配置一致,且已调试确认消息的JMSXGroupID属性已正确设置,期望应用能正常向Premium层会话队列发送消息。

相关代码

消息生产者Bean代码:

private void sendMessageToQueue(Queue queue, Object payload, boolean setGroupId)
{
    jmsTemplate.convertAndSend(queue, payload, (Message message) ->
    {
        if (setGroupId)
        {
            setGroupId(message);
        }
        return message;
    });
}

setGroupId方法实现:

void setGroupId(Message message)
{
    try
    {
        message.setStringProperty("JMSXGroupID","0");
    }
    catch (JMSException e)
    {
        LOG.error("Setting of JMSXGroupID failed with exception: {}", e.getMessage());
    }
}

问题原因与解决方法

Premium层Service Bus会话队列对AMQP协议层面的SessionId要求更严格:标准层会自动将JMSXGroupID映射为会话标识,但Premium层不会执行该自动映射,必须显式设置SessionId(对应JMS属性JMS_AMQP_SESSION_ID)。

修改setGroupId方法,同时设置JMS_AMQP_SESSION_ID属性即可解决问题:

void setGroupId(Message message)
{
    try
    {
        String groupId = "0";
        message.setStringProperty("JMSXGroupID", groupId);
        // 针对Premium层添加SessionId设置
        message.setStringProperty("JMS_AMQP_SESSION_ID", groupId);
    }
    catch (JMSException e)
    {
        LOG.error("Setting of JMSXGroupID failed with exception: {}", e.getMessage());
    }
}

内容的提问来源于stack exchange,提问作者LaserEule

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 01:04:59