Wildfy JMS 主题消耗空值

问题描述 投票:0回答:1

我正在使用 Wildfy 19 和 JMS(主题)应用程序。运行该程序后,它返回空值。 `

try {
            final Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
            env.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
            env.put(Context.SECURITY_PRINCIPAL, "jmsuser");
            env.put(Context.SECURITY_CREDENTIALS, "Password1!");
            namingContext = new InitialContext(env);

            ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup("jms/RemoteConnectionFactory");
            Destination destination = (Destination) namingContext .lookup("jms/topic/myTopic");
            context = connectionFactory.createContext("jmsuser", "Password1!");
            context.createProducer().send(destination, "mymeninsgh city topic !");
            System.out.println("Sent message successuflly ");

            JMSConsumer consumer = context.createConsumer(destination);
            String text = consumer.receiveBody(String.class, 5000);
            System.out.println("Received message with content " + text);

        } catch (Exception e) {
            System.out.println(e.getMessage());
            throw e;
        } finally {
            if (namingContext != null) {
                namingContext.close();
            }
            if (context != null) {
                context.close();
            }
        }`

Wildfy 主题配置是:

enter image description here

运行此程序后,出现以下错误:

Sent message successuflly 
Received message with content null

如何解决这个错误(null)? 我怎样才能获得实际值而不是 null ?

java jakarta-ee jms activemq-artemis
1个回答
0
投票

您所看到的是“预期行为”,因为您在创建使用者之前将消息发送到 JMS 主题。这是因为 JMS 主题遵循发布/订阅语义,这规定在创建任何订阅之前发送的消息将被丢弃。 您应该:

首先创建您的消费者,然后
    然后
  • 发送消息。 将消息发送到 JMS
  • 队列
© www.soinside.com 2019 - 2024. All rights reserved.