如何解决“已经存在的值:AMQChannel(amqp:// guest @ 0:0:0:0:0:0:0:1:5672 /,1)”

时间:2019-01-16 17:02:22

标签: java rabbitmq client channel bimap

我正在编程RabbitMQ服务器客户端应用程序。我想用一个名称将客户端通道保存在BiMap中。可以,但是如果有两个客户端,则会发生错误

java.lang.IllegalArgumentException: value already present: AMQChannel(amqp://guest@0:0:0:0:0:0:0:1:5672/,1)
    at com.google.common.collect.HashBiMap.put(HashBiMap.java:279)
    at com.google.common.collect.HashBiMap.put(HashBiMap.java:260)
    at net.skillergames.skillercloud.rabbitmq.RabbitManager.handlePacket(RabbitManager.java:48)
    at net.skillergames.skillercloud.rabbitmq.RabbitConnection$1.handleDelivery(RabbitConnection.java:52)
    at net.skillergames.skillercloud.rabbitmq.PacketConsumer.handleDelivery(PacketConsumer.java:26)
    at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
    at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我已经使用普通的哈希映射进行了尝试,但是无法使用.inverse()进行旋转

public void handlePacket(Channel channel, Packet packet) {
  byte packetID = packet.getId();
  Document data = packet.getData();
  switch(packetID) {
    case 0x01:
      String serverName = data.getString("serverName");
      getChannels().put(data.getString("serverName").replace("Proxy|","").replace("Server|", ""), channel);

输出是该频道已注册,如何保存频道,这样我可以为每个频道添加一个名称,反之亦然

0 个答案:

没有答案