public MessageProperties toMessageProperties(
     final BasicProperties source, final Envelope envelope, final String charset) {
   MessageProperties target = new MessageProperties();
   Map<String, Object> headers = source.getHeaders();
   if (!CollectionUtils.isEmpty(headers)) {
     for (Map.Entry<String, Object> entry : headers.entrySet()) {
       String key = entry.getKey();
       if (MessageProperties.X_DELAY.equals(key)) {
         Object value = entry.getValue();
         if (value instanceof Integer) {
           target.setReceivedDelay((Integer) value);
         }
       } else {
         target.setHeader(key, convertLongStringIfNecessary(entry.getValue(), charset));
       }
     }
   }
   target.setTimestamp(source.getTimestamp());
   target.setMessageId(source.getMessageId());
   target.setReceivedUserId(source.getUserId());
   target.setAppId(source.getAppId());
   target.setClusterId(source.getClusterId());
   target.setType(source.getType());
   Integer deliveryMode = source.getDeliveryMode();
   if (deliveryMode != null) {
     target.setReceivedDeliveryMode(MessageDeliveryMode.fromInt(deliveryMode));
   }
   target.setDeliveryMode(null);
   target.setExpiration(source.getExpiration());
   target.setPriority(source.getPriority());
   target.setContentType(source.getContentType());
   target.setContentEncoding(source.getContentEncoding());
   String correlationId = source.getCorrelationId();
   if (StringUtils.hasText(correlationId)) {
     target.setCorrelationId(source.getCorrelationId());
   }
   String replyTo = source.getReplyTo();
   if (replyTo != null) {
     target.setReplyTo(replyTo);
   }
   if (envelope != null) {
     target.setReceivedExchange(envelope.getExchange());
     target.setReceivedRoutingKey(envelope.getRoutingKey());
     target.setRedelivered(envelope.isRedeliver());
     target.setDeliveryTag(envelope.getDeliveryTag());
   }
   return target;
 }
 public static MessageProperties valueOf(BasicProperties bp) {
   MessageProperties mp = new MessageProperties();
   mp.setAppId(bp.getAppId());
   mp.setClusterId(bp.getClusterId());
   mp.setContentEncoding(bp.getContentEncoding());
   mp.setContentType(bp.getContentType());
   mp.setCorrelationId(bp.getCorrelationId());
   mp.setDeliveryMode(bp.getDeliveryMode());
   mp.setExpiration(bp.getExpiration());
   mp.setHeaders(bp.getHeaders());
   mp.setMessageId(bp.getMessageId());
   mp.setPriority(bp.getPriority());
   mp.setReplyTo(bp.getReplyTo());
   mp.setTimestamp(bp.getTimestamp());
   mp.setType(bp.getType());
   mp.setUserId(bp.getUserId());
   return mp;
 }
    @Override
    public void run() {
      try {
        Connection connection = factory.newConnection();
        String uuid = UUID.randomUUID().toString();
        String queueName = RPC_QUEUE_NAME + uuid;
        Map<String, Channel> result =
            this.server.initChannel(connection, this.assignedNumber, queueName);
        Channel consumerChannel = result.get("consumer");

        Channel publisherChannel = result.get("publisher");

        QueueingConsumer consumer = new QueueingConsumer(consumerChannel);
        consumerChannel.basicConsume(queueName, true, consumer);
        System.out.println("in server ");
        while (true) {
          QueueingConsumer.Delivery delivery = consumer.nextDelivery();
          // System.out.printf("delivery is %s, body is %s", delivery, new
          // String(delivery.getBody()));
          BasicProperties props = delivery.getProperties();
          // System.out.printf("correlationId is %s", props.getCorrelationId());
          BasicProperties replyProps =
              new BasicProperties.Builder()
                  .correlationId(props.getCorrelationId())
                  .messageId(props.getMessageId())
                  .build();

          String response = new String(delivery.getBody());
          // System.out.printf("response is %s", new String(delivery.getBody()));
          // System.out.printf("reply to is %s",  props.getReplyTo()        );
          publisherChannel.basicPublish(
              PUBLISHER_EXCHANGE_NAME, props.getReplyTo(), replyProps, response.getBytes());

          // consumerChannel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }