Cause: Broker: localhost – Client: tata_consumer 已经从 tcp://127.0.0.1:52917 连接。

huangapple go评论80阅读模式
英文:

Cause: Broker: localhost - Client: tata_consumer already connected from tcp://127.0.0.1:52917

问题

我是ActiveMQ的新手,正在尝试实验主题的工作方式。我已经使用JMS创建了一个生产者,还使用Spring配置了两个消费者监听器。我知道如果使用多个消费者,那么每个消费者都应该有一个唯一的客户端ID。即使保持客户端ID唯一,我仍然遇到相同的错误。

错误信息如下:

ERROR | 无法为目标'destination'刷新JMS连接'hetal_rachh_topic' - 重试,使用FixedBackOff{interval=5000, currentAttempts=4, maxAttempts=unlimited}。原因:Broker: localhost - Client: tata_consumer已经连接于tcp://127.0.0.1:52917
ERROR | 无法为目标'destination'刷新JMS连接'hetal_rachh_topic' - 重试,使用FixedBackOff{interval=5000, currentAttempts=4, maxAttempts=unlimited}。原因:Broker: localhost - Client: cipla_consumer已经连接于tcp://127.0.0.1:52918


**注意:我甚至尝试只创建一个JMS监听容器,但错误仍然显示特定的客户端已经连接。**

我正在尝试做以下步骤:

1. 创建了一个Maven项目,其中包含一个带有两个API的REST控制器。第一个API只是初始化一个ArrayList。第二个API调用一个使用JMSTemplate发送消息到主题的生产者。
2. 在Spring上下文文件中配置了一个JMS监听器。
3. UI代码使用axios调用第一个API,该API初始化一些ArrayList。然后,在每个间隔之后,调用第二个API,该API调用生产者发送消息,然后由监听器消费。控制器(第二个API)基本上将收到的消息的JSON字符串返回给UI。
4. 我本地没有使用任何Web服务器,而是使用tomcat7插件运行我的Spring项目`mvn tomcat7:run`。我启动了一个本地AMQ服务器`activemq start`,并使用`npm start`启动我的UI代码。

以下是我的ReactJs UI代码片段,其中使用了axios进行调用。

```javascript
componentDidMount() {
    this.callCreateConnection();
    this.interval = setInterval(this.callStockUpdatesAPI, 15000);
}

componentWillUnmount() {
    clearInterval(this.interval);
}

async callCreateConnection() {
    await axios
        .get("http://localhost:8080/stock-market-ticker/createConnection", {
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "GET",
            },
        })
        .then((res) => {
            console.log("Response", res.data);
        })
        .catch((error) => {
            console.log("Error", error);
        });
}

// 省略部分代码...

async callStockUpdatesAPI() {
    // ...
}

我在https://github.com/hetalrachh/stock-market-ticker 上共享了我的Spring应用程序代码。

如何修复这个问题?如果有人能提供帮助,提前致谢。


<details>
<summary>英文:</summary>

I am new to ActiveMQ and trying to experiment working of topics. I have created a Producer using JMS and two Consumer listeners configured using Spring. I do know that if multiple consumers are used then every consumer should have a unique client id. Even after keeping the client id&#39;s unique, I get the same error.

ERROR | Could not refresh JMS Connection for destination 'hetal_rachh_topic' - retrying using FixedBackOff{interval=5000, currentAttempts=4, maxAttempts=unlimited}. Cause: Broker: localhost - Client: tata_consumer already connected from tcp://127.0.0.1:52917
ERROR | Could not refresh JMS Connection for destination 'hetal_rachh_topic' - retrying using FixedBackOff{interval=5000, currentAttempts=4, maxAttempts=unlimited}. Cause: Broker: localhost - Client: cipla_consumer already connected from tcp://127.0.0.1:52918


**Note: I even tried creating just one JMS listener container and still the error says that the particular client is already connected.**

Steps of what I am trying to do -

1. Created a maven project with a REST controller having two API&#39;s. First API just initializes an arraylist. And second API calls a producer which sends message to topic using JMSTemplate.
2. Configured just one JMS listener in the spring context file
2. The UI code uses axios to make a call to the first API which initializes some arraylist. And then after every interval, calls the second API which calls producer to send messages which are further consumed by the listeners. The controller (second API) basically returns the JSON string of the messages received back to the UI.
3. I am not using any web server locally but tomcat7 plugin to run my spring project `mvn tomcat7:run`. I start a local AMQ server `activemq start` and start my UI code using `npm start`

Below is my ReactJs UI code snippet which makes axios calls.

    componentDidMount() {
        this.callCreateConnection();
        this.interval = setInterval(this.callStockUpdatesAPI, 15000);
      }
    
      componentWillUnmount() {
        clearInterval(this.interval);
      }
    
      async callCreateConnection() {
        await axios
          .get(&quot;http://localhost:8080/stock-market-ticker/createConnection&quot;, {
            headers: {
              &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot;,
              &quot;Access-Control-Allow-Methods&quot;: &quot;GET&quot;,
            },
          })
          .then((res) =&gt; {
            console.log(&quot;Response&quot;, res.data);
          })
          .catch((error) =&gt; {
            console.log(&quot;Error&quot;, error);
          });
      }
    
      async callStockUpdatesAPI() {
        console.log(&quot;Inside api&quot;);
        await axios
          .get(&quot;http://localhost:8080/stock-market-ticker/getStockUpdates&quot;, {
            headers: {
              &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot;,
              &quot;Access-Control-Allow-Methods&quot;: &quot;GET&quot;,
            },
          })
          .then((response) =&gt; {
            console.log(&quot;Response&quot;, response.data);
            switch (response.data.symbol) {
              case &quot;TATAMOTORS&quot;:
                let oldData_tata = { ...this.state.data };
    
                oldData_tata[0].price = response.data.price;
                oldData_tata[0].percent_change_1h = response.data.change_1hr;
                oldData_tata[0].percent_change_24h = response.data.change_24hr;
                this.setState({ data: oldData_tata });
    
                break;
              case &quot;CIPLA&quot;:
                let oldData_cipla = { ...this.state.data };
                oldData_cipla[0].price = response.data.price;
                oldData_cipla[0].percent_change_1h = response.data.change_1hr;
                oldData_cipla[0].percent_change_24h = response.data.change_24hr;
                this.setState({ data: oldData_cipla });
    
                break;
              case &quot;ASIANPAINT&quot;:
                let oldData_asian = { ...this.state.data };
                oldData_asian[1].price = response.data.price;
                oldData_asian[1].percent_change_1h = response.data.change_1hr;
                oldData_asian[1].percent_change_24h = response.data.change_24hr;
                this.setState({ data: oldData_asian });
    
                break;
              default:
                return;
            }
          })
          .catch((error) =&gt; {
            console.log(&quot;Error&quot;, error);
          });
     }

I have shared my Spring application code at https://github.com/hetalrachh/stock-market-ticker.

How can I fix this? If anyone can help. Thanks in advance.

</details>


# 答案1
**得分**: 1

我认为问题在于每个Spring `listener-container` 正在创建 *多个* 监听器,而每个这些多个监听器都在使用来自其父容器的相同 `client-id` 值。这在JMS规范中是不允许的。尝试在你的 `listener-container` 元素上使用 `concurrency=&quot;1&quot;`,例如:

```xml
    &lt;jms:listener-container acknowledge=&quot;auto&quot;
        connection-factory=&quot;connectionFactory&quot; destination-type=&quot;durableTopic&quot;
        client-id=&quot;tata_consumer&quot; concurrency=&quot;1&quot;&gt;
        &lt;jms:listener destination=&quot;hetal_rachh_topic&quot; ref=&quot;tataConsumer&quot;
            method=&quot;onMessage&quot; subscription=&quot;subscription&quot; selector=&quot;symbol=TATAMOTORS&quot; /&gt;
    &lt;/jms:listener-container&gt;

    &lt;jms:listener-container acknowledge=&quot;auto&quot;
        connection-factory=&quot;connectionFactory&quot; destination-type=&quot;durableTopic&quot;
        client-id=&quot;cipla_consumer&quot; concurrency=&quot;1&quot;&gt;
        &lt;jms:listener destination=&quot;hetal_rachh_topic&quot; ref=&quot;ciplaConsumer&quot;
            method=&quot;onMessage&quot; subscription=&quot;subscription&quot; selector=&quot;symbol=CIPLA&quot; /&gt;
    &lt;/jms:listener-container&gt;
英文:

I believe the problem is that each Spring listener-container is creating multiple listeners, and each of those multiple listeners is using the same client-id value from it's parent container. This is not allowed by the JMS specification. Try using concurrency=&quot;1&quot; on your listener-container elements, e.g.:

    &lt;jms:listener-container acknowledge=&quot;auto&quot;
        connection-factory=&quot;connectionFactory&quot; destination-type=&quot;durableTopic&quot;
        client-id=&quot;tata_consumer&quot; concurrency=&quot;1&quot;&gt;
        &lt;jms:listener destination=&quot;hetal_rachh_topic&quot; ref=&quot;tataConsumer&quot;
            method=&quot;onMessage&quot; subscription=&quot;subscription&quot; selector=&quot;symbol=TATAMOTORS&quot; /&gt;
    &lt;/jms:listener-container&gt;

    &lt;jms:listener-container acknowledge=&quot;auto&quot;
        connection-factory=&quot;connectionFactory&quot; destination-type=&quot;durableTopic&quot;
        client-id=&quot;cipla_consumer&quot; concurrency=&quot;1&quot;&gt;
        &lt;jms:listener destination=&quot;hetal_rachh_topic&quot; ref=&quot;ciplaConsumer&quot;
            method=&quot;onMessage&quot; subscription=&quot;subscription&quot; selector=&quot;symbol=CIPLA&quot; /&gt;
    &lt;/jms:listener-container&gt;


</details>



huangapple
  • 本文由 发表于 2020年5月3日 20:39:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/61574587.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定