Exemplo n.º 1
0
  @Override
  public boolean endSubscribtionToChannel(String exchangeName) {
    Channel channel = subscribedChannels.get(exchangeName);
    if (channel != null) {
      try {
        String queueName = channel.queueDeclare().getQueue();
        channel.queueUnbind(queueName, exchangeName, "");
        //				channel.basicConsume(queueName, arg1)

        //				channel.close(0,exchangeName);
        subscribedChannels.remove(exchangeName);
        channel = null;
        Log.i(
            LOGTAG,
            "subscribed to "
                + subscribedChannels.size()
                + " Channels"
                + "\n"
                + "ended subscribtion to : "
                + exchangeName);
        return true;
      } catch (AlreadyClosedException e) {
        Log.e(LOGTAG, "endSubcribtionToChannel: " + e.toString());
        subscribedChannels.remove(exchangeName);
      } catch (IOException e) {
        Log.e(LOGTAG, "endSubcribtionToChannel: " + e.toString());
      } catch (ShutdownSignalException e) {
        Log.e(LOGTAG, "endSubcribtionToChannel: " + e.toString());
      }
    }
    return false;
  }
Exemplo n.º 2
0
 @Override
 public boolean sendStringOnChannel(String string, String exchangeName) {
   try {
     Channel channel = subscribedChannels.get(exchangeName);
     if (channel != null) {
       channel.basicPublish(exchangeName, "", null, string.getBytes());
     }
     Log.i(LOGTAG, "send to: " + exchangeName);
     return true;
   } catch (AlreadyClosedException exception) {
     Log.e(LOGTAG, exchangeName + " : " + exception.toString());
     subscribedChannels.remove(exchangeName);
   } catch (IOException e) {
     Log.e(LOGTAG, "sendStringOnChannel: " + e.toString());
   }
   return false;
 }