当前位置: 首页 > 知识库问答 >
问题:

无法在主题中创建持久订户

酆恩
2023-03-14

参考Link,我使用JMS ActiveMQ SpringBoot创建了持久订阅者。我还使用UUID.randomUUID()生成了惟一的客户机ID。toString()。然而,在启动订户(接收器)时,应用程序抛出以下警告消息

Cause: Durable consumer is in use for client: 8f1019fd-50d4-457b-b417-2058917ed7bb and subscriptionName: org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter


请帮我删除上述警告信息。

@SpringBootApplication
@EnableJms
public class ReceiverTopicApplicaton {
public static void main(String[] args) {
        SpringApplication.run(ReceiverTopicApplicaton.class, args);
    }


    private ConnectionFactory connectionFactory() {
        return new ActiveMQConnectionFactory("tcp://localhost:61616");
    }

    @Bean
    public DefaultJmsListenerContainerFactory topicListenerFactory() {
        DefaultJmsListenerContainerFactory factory =
                new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        //we need to set destinationResolver() to remove the warning message
        factory.setDestinationResolver(destinationResolver());
        factory.setPubSubDomain(true); 
        factory.setSubscriptionDurable(true);
        factory.setConcurrency("3-10");
        factory.setClientId(UUID.randomUUID().toString());
        factory.setSubscriptionDurable(true);
        return factory;
    }

Receiver.java

@Component
public class Receiver {

    @JmsListener(destination = "durable.topic", containerFactory = "topicListenerFactory")
    public void receiveMessage(final Message message) throws JMSException {
        if (message instanceof ObjectMessage) {
            Object object = ((ObjectMessage) message).getObject();
            StudentDto studentDto = (StudentDto) object;
            System.out.println("Receiver :: Student Object Received..." + studentDto);
        }
    }

}

学生.java

public class StudentDto implements Serializable {

    private Long studentId; 
    private String studentName; 
    private String gender;
    private Long age;   
    private String studentClass;    
    private LocalDate birthDate;

    public StudentDto() {}

    public StudentDto(Long studentId, String studentName,String gender,Long age,String studentClass, LocalDate birthDate) {
        this.studentId = studentId;
        this.studentName = studentName;
        this.gender = gender;
        this.age = age;
        this.studentClass = studentClass;
        this.birthDate = birthDate;
    }

    @Override
    public String toString() {
        return "Student [studentId=" + studentId + ", studentName=" + studentName + ", Gender=" + gender + ", Age="
                + age + ", studentClass=" + studentClass + ", birthDate=" + birthDate + "]";
    }
}

SendMessageApplication.java

@SpringBootApplication
@EnableJms
public class SendMessageApplication {

    public static void main(String[] args) {
        SpringApplication.run(SendMessageApplication.class, args);
    }

    @Bean
    public JmsListenerContainerFactory<?> topicListenerFactory(
            ConnectionFactory connectionFactory,
            DefaultJmsListenerContainerFactoryConfigurer configurer)       
    {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        configurer.configure(factory, connectionFactory);
        factory.setPubSubDomain(true); 
        return factory;
    }

主题发送消息.java

@RestController
@RequestMapping(path = "/schoolDashboard/topic")
class TopicSendMessage {

    @Autowired
    private JmsTemplate jmsTemplate;

    @GetMapping(path = "/publishMessage")
    public void sendMessage() throws Exception{
        String birthDate = "1978-10-05";
        StudentDto studentDto = new StudentDto(new Long(1), "Ritesh", "Male", new Long(12), "Class-V", LocalDate.parse(birthDate));
        System.out.println("TopicSendMessage.java :: Topic - Publishing Student Object....");               
        jmsTemplate.setPubSubDomain(true);
        jmsTemplate.convertAndSend("student.topic", studentDto);
    }
}

共有1个答案

董昕
2023-03-14

因为您使用的是ActiveMQ 5.x,所以使用的是JMS 1.1,JMS 1.2规范规定,一个持久订阅只能有一个订阅服务器。由于您使用的是setConcurrency(“3-10”)Spring试图在同一个持久订阅上创建多个订阅服务器,这导致了您看到的错误。您应该:

  • 使用集合时间(“1”)。这可能会导致性能显著下降。
  • 移动到支持 JMS 2.0(如 ActiveMQ Artemis)的代理,并调用 set订阅共享(true),因为 JMS 2.0 在持久订阅的多个订阅者方面没有与 JMS 1.1 相同的限制。
 类似资料:
  • 我需要为ActiveMQ创建一个主题和一个持久订阅者,我的问题是我不知道在哪里指定它。我可以创建主题并使用消息,但是当我关闭订阅者然后继续发送消息并再次打开订阅者时,它不会读取它们。 这是我目前掌握的情况: 发送消息: 接收消息: 我已经阅读了这篇文章,我明白我需要创建持久订阅者。 我也读过spring文档 我认为它与(我没有实现,我使用的是默认配置)有关,文档显示: 但是我似乎找不到在哪里创建持

  • 在我们的业务需求中,我们需要将更新传输到分布在全国各地的数千个客户端。问题是,许多这些客户端使用3G网络连接到我们,因此,发生了许多连接/断开连接...我们需要提供的更新是诸如“企业A不能再兑现”或“企业B能够再次兑现”之类的东西,我们正在考虑使用ActiveMQ持久主题来提供这些更新。我的理解是,一旦客户端连接到持久主题,即使他断开连接,每当他回来时,他都会在脱机时收到发送到该主题的消息。最大的

  • 我正在尝试使用JMS在Azure Service Bus上创建非持久主题订阅。此功能最近已用于高级服务总线层。 我知道连接本身不是问题,因为我可以用这个连接工厂在主题中发布。我想知道是否有义务使用服务总线连接工厂或是否有解决方案。

  • 我有疑问一条消息是否会在主题中持续存在,我从这篇文章中得到了大部分答案。 但是这种情况如何呢?假设代理重新开始,一些发布者已经开始向一个主题发送消息,现在将来一些持久订户将与该主题连接,但是当前没有持久订户,因此在代理重新开始的情况下,发布者到目前为止向该主题发送的所有消息都将丢失。 我尝试了上述情况,确实所有的信息都丢失了。此外,我尝试了这种情况——我有一个活跃的持久订阅者,它能够将消息推送到主

  • 问题内容: 我曾经用PHP启动会话,但是当我的浏览器关闭时,该会话消失了。 如何使用PHP创建持续持续浏览器关闭的持久会话? 问题答案: 请参阅值session.cookie_lifetime。 默认值意味着在浏览器关闭时结束会话。 您可以使用ini_set在开始会话之前直接在应用程序中覆盖此值或在应用程序中设置它。将其设置为大于此值将导致会话在该持续时间内存活。 例如 上面的示例使会话cooki

  • Atom的界面使用HTML渲染,并且通过Less来定义样式,它是CSS的超集。不要担心之前从未听说过Less,它类似于CSS,但是带有一些便捷的扩展。 Atom支持两种主题:UI和语法。UI主题为树视图、选择夹、下拉列表和状态栏之类的元素定义样式。语法主题为编辑器中的代码定义样式。 主题可以从设置视图安装和修改,你可以选择Atom > Preferences…菜单,然后在左侧的侧栏中选择“Inst