Exemplo n.º 1
0
  public static void main(String[] argv) throws IOException {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("datdb.cphbusiness.dk");
    factory.setUsername("student");
    factory.setPassword("cph");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
    String queueName = "Kender du hende der Arne";
    channel.queueDeclare(queueName, false, false, false, null);

    channel.queueBind(queueName, EXCHANGE_NAME, "");
    String messageOut =
        "{\"ssn\":1605789787,\"creditScore\":699,\"loanAmount\":10.0,\"loanDuration\":360}";
    BasicProperties.Builder props = new BasicProperties().builder();
    props.replyTo("");
    BasicProperties bp = props.build();
    channel.basicPublish(EXCHANGE_NAME, "", bp, messageOut.getBytes());
    System.out.println(" [x] Sent by JSONtester: '" + messageOut + "'");

    channel.close();
    connection.close();
  }
 public BasicProperties fromMessageProperties(
     final MessageProperties source, final String charset) {
   BasicProperties.Builder target = new BasicProperties.Builder();
   target
       .headers(this.convertHeadersIfNecessary(source.getHeaders()))
       .timestamp(source.getTimestamp())
       .messageId(source.getMessageId())
       .userId(source.getUserId())
       .appId(source.getAppId())
       .clusterId(source.getClusterId())
       .type(source.getType());
   MessageDeliveryMode deliveryMode = source.getDeliveryMode();
   if (deliveryMode != null) {
     target.deliveryMode(MessageDeliveryMode.toInt(deliveryMode));
   }
   target
       .expiration(source.getExpiration())
       .priority(source.getPriority())
       .contentType(source.getContentType())
       .contentEncoding(source.getContentEncoding());
   String correlationId = source.getCorrelationId();
   if (StringUtils.hasText(correlationId)) {
     target.correlationId(correlationId);
   }
   String replyTo = source.getReplyTo();
   if (replyTo != null) {
     target.replyTo(replyTo);
   }
   return target.build();
 }
Exemplo n.º 3
0
 private BasicProperties convertProperties(MessageProperties properties) {
   if (properties == null) {
     return null;
   }
   // TODO: Figure out a better way to share this data and not duplicate
   BasicProperties.Builder props = new BasicProperties.Builder();
   props.appId(properties.getAppId());
   // props.setClusterId(?);
   props.contentEncoding(properties.getContentEncoding());
   props.contentType(properties.getContentType());
   props.correlationId(properties.getCorrelationId());
   if (properties.getDeliveryMode() != null) {
     props.deliveryMode(properties.getDeliveryMode().getMode());
   }
   props.expiration(properties.getExpiration());
   props.headers(properties.getHeaders());
   props.messageId(properties.getMessageId());
   props.priority(properties.getPriority());
   props.replyTo(properties.getReplyTo());
   props.timestamp(properties.getTimestamp());
   props.type(properties.getType());
   props.userId(properties.getUserId());
   return props.build();
 }