当前位置: 首页>>代码示例>>Java>>正文


Java AMQP.BasicProperties方法代码示例

本文整理汇总了Java中com.rabbitmq.client.AMQP.BasicProperties方法的典型用法代码示例。如果您正苦于以下问题:Java AMQP.BasicProperties方法的具体用法?Java AMQP.BasicProperties怎么用?Java AMQP.BasicProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rabbitmq.client.AMQP的用法示例。


在下文中一共展示了AMQP.BasicProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
/**
 * @param args
 * @throws IOException
 * @throws TimeoutException
 * @date 2017年7月13日 下午2:57:32
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();
	// 声明交换器
	channel.exchangeDeclare(EXCHANGE_NAME_ROUTING, "direct");
	// 获取匿名队列名称
	String queueName = channel.queueDeclare().getQueue();
	// 根据路由关键字进行多重绑定
	for (String severity : routingKeys2) {
		channel.queueBind(queueName, EXCHANGE_NAME_ROUTING, severity);
		System.out.println("ReceiveLogsDirect2 exchange:" + EXCHANGE_NAME_ROUTING + ", queue:" + queueName
				+ ", BindRoutingKey:" + severity);
	}
	System.out.println("ReceiveLogsDirect2 Waiting for messages");

	Consumer consumer = new DefaultConsumer(channel) {
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws UnsupportedEncodingException {
			String message = new String(body, "UTF-8");
			System.out.println("ReceiveLogsDirect2 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
		}
	};
	channel.basicConsume(queueName, true, consumer);

}
 
开发者ID:pudoj,项目名称:june.mq,代码行数:40,代码来源:ReceiveLogsDirect2.java

示例2: send

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
public int send(String mqName, JSONObject message, String replyMq){
	/*Used when you want to send a new msg to the specified MQ
	 *Side effect: correlation Id and replyMq name will be stored in 
	 * this object only
	 */
	try {
		if(channel==null)
			connectToBroker();
		String routingKey = mqName;
		AMQP.BasicProperties props = new AMQP.BasicProperties
				.Builder()
				.replyTo(replyMq)
				.build();
		channel.basicPublish(defaultExchange, routingKey, props, message.toString().getBytes("UTF-8"));
		replyMqName = replyMq;
	}
	catch(Exception e){
		e.printStackTrace();
		return 0;
	}
	return 1;
}
 
开发者ID:hemantverma1,项目名称:ServerlessPlatform,代码行数:23,代码来源:communicateWithMQ.java

示例3: sendWithHeader

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
public int sendWithHeader(String mqName, JSONObject message, String replyMq, Map<String, Object> headersMap){
	/*Used when you want to send a new msg to the specified MQ with header-fields set in the msg headers
	 *Side effect: correlation Id and replyMq name will be stored in 
	 * this object only
	 */
	try {
		if(channel==null)
			connectToBroker();
		String routingKey = mqName;
		AMQP.BasicProperties props = new AMQP.BasicProperties
				.Builder()
				.replyTo(replyMq)
				.headers(headersMap)
				.build();
		channel.basicPublish(defaultExchange, routingKey, props, message.toString().getBytes("UTF-8"));
		replyMqName = replyMq;
	}
	catch(Exception e){
		e.printStackTrace();
		return 0;
	}
	return 1;
}
 
开发者ID:hemantverma1,项目名称:ServerlessPlatform,代码行数:24,代码来源:communicateWithMQ.java

示例4: handleDelivery

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
    // decode internal message
    InternalMessage msg = JSONs.decodeInternalMessage(body);

    // notify listener
    if (msg != null) {
        logger.debug("Communicator received: Received {} message for client {} user {}", msg.getMessageType(), msg.getClientId(), msg.getUserName());
        switch (msg.getMessageType()) {
            case PUBLISH:
                listener.onPublish((InternalMessage<Publish>) msg);
                break;
            case DISCONNECT:
                listener.onDisconnect((InternalMessage<Disconnect>) msg);
                break;
            default:
                logger.warn("Communicator error: Communicator received unexpected message type {}", msg.getMessageType());
        }
    }
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:22,代码来源:RabbitMQBrokerConsumer.java

示例5: sourceRecord

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
SourceRecord sourceRecord(String consumerTag, Envelope envelope, AMQP.BasicProperties basicProperties, byte[] bytes) {
  Struct key = MessageConverter.key(basicProperties);
  Struct value = MessageConverter.value(consumerTag, envelope, basicProperties, bytes);
  final String topic = this.config.kafkaTopic.execute(RabbitMQSourceConnectorConfig.KAFKA_TOPIC_TEMPLATE, value);

  return new SourceRecord(
      ImmutableMap.of("routingKey", envelope.getRoutingKey()),
      ImmutableMap.of("deliveryTag", envelope.getDeliveryTag()),
      topic,
      null,
      key.schema(),
      key,
      value.schema(),
      value,
      null == basicProperties.getTimestamp() ? this.time.milliseconds() : basicProperties.getTimestamp().getTime()
  );
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-rabbitmq,代码行数:18,代码来源:SourceRecordBuilder.java

示例6: receiveTopicMessage

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
/**
 * 接受主题消息
 */
public void receiveTopicMessage() throws IOException, TimeoutException {
    RabbitMQChannel channel = new RabbitMQChannel().channel();
    channel.getChannel().exchangeDeclare(TOPIC, "topic");
    String queueName = channel.getChannel().queueDeclare().getQueue();
    channel.getChannel().queueBind(queueName, TOPIC, "bindingKey");
    System.out.println("等待接受topic主题【" + TOPIC + "】消息");
    System.out.println("选择队列:" + queueName);
    Consumer consumer = new DefaultConsumer(channel.getChannel()) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope,
                                   AMQP.BasicProperties properties, byte[] body) throws IOException {
            String message = new String(body, "UTF-8");
            System.out.println("接受消息:" + envelope.getRoutingKey() + "':'" + message + "'");
        }
    };
    channel.getChannel().basicConsume(queueName, true, consumer);
}
 
开发者ID:mumudemo,项目名称:mumu-rabbitmq,代码行数:21,代码来源:RabbitMQTopic.java

示例7: preProcess

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
@Override
public void preProcess(Consumer t, Object proxy, Method method, Object[] args) {

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, url);
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, "Consumer." + method.getName());
    params.put(CaptureConstants.INFO_CLIENT_APPID, applicationId);
    params.put(CaptureConstants.INFO_CLIENT_TYPE, "rabbitmq.client");

    if (logger.isDebugable()) {
        logger.debug("Invoke START:" + url + ",op=Consumer." + method.getName(), null);
    }

    UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
            Monitor.CapturePhase.PRECAP, params);
    // 调用链只关心真正消费消息
    if (method.getName().equals("handleDelivery")) {

        AMQP.BasicProperties props = (BasicProperties) args[2];
        if (props.getHeaders() != null
                && props.getHeaders().containsKey(InvokeChainConstants.PARAM_MQHEAD_SPANINFO)) {
            params.put(InvokeChainConstants.PARAM_MQHEAD_SPANINFO,
                    props.getHeaders().get(InvokeChainConstants.PARAM_MQHEAD_SPANINFO) + "");
            params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL, url);
        }

        // register adapter
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter",
                "registerAdapter", RabbitmqConsumerAdapter.class);

        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap",
                InvokeChainConstants.CHAIN_APP_SERVICE, InvokeChainConstants.CapturePhase.PRECAP, params,
                RabbitmqConsumerAdapter.class, args);
    }

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:37,代码来源:RabbitmqIT.java

示例8: extract

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
public static SpanContext extract(AMQP.BasicProperties props, Tracer tracer) {
  SpanContext spanContext = tracer
      .extract(Format.Builtin.TEXT_MAP, new HeadersMapExtractAdapter(props.getHeaders()));
  if (spanContext != null) {
    return spanContext;
  }

  Span span = tracer.activeSpan();
  if (span != null) {
    return span.context();
  }
  return null;
}
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:14,代码来源:TracingUtils.java

示例9: convertToStreamedTuple

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
@Override
public final StreamedTuple convertToStreamedTuple(Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws Exception {
    List<Object> tuple = convertToTuple(envelope, properties, body);
    if (tuple == null || tuple.isEmpty()) {
        return null;
    } else {
        return new StreamedTuple(streamId, tuple);
    }
}
 
开发者ID:anderelate,项目名称:storm-rabbitmq,代码行数:10,代码来源:SingleStreamRabbitMqMessageScheme.java

示例10: handleDelivery

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
    // decode internal message
    InternalMessage msg = JSONs.decodeInternalMessage(body);

    // notify listener
    if (msg != null) {
        logger.debug("Communicator received: Received {} message from broker {} for client {} user {}", msg.getMessageType(), msg.getBrokerId(), msg.getClientId(), msg.getUserName());
        switch (msg.getMessageType()) {
            case CONNECT:
                this.listener.onConnect((InternalMessage<Connect>) msg);
                break;
            case PUBLISH:
                this.listener.onPublish((InternalMessage<Publish>) msg);
                break;
            case SUBSCRIBE:
                this.listener.onSubscribe((InternalMessage<Subscribe>) msg);
                break;
            case UNSUBSCRIBE:
                this.listener.onUnsubscribe((InternalMessage<Unsubscribe>) msg);
                break;
            case DISCONNECT:
                this.listener.onDisconnect((InternalMessage<Disconnect>) msg);
                break;
            default:
                logger.warn("Communicator error: Communicator received unexpected message type {}", msg.getMessageType());
        }
    }
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:31,代码来源:RabbitMQApplicationConsumer.java

示例11: basicPublish

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
@Override
public void basicPublish(String exchange, String routingKey, boolean mandatory, boolean immediate,
    AMQP.BasicProperties props, byte[] body) throws IOException {

  try (Scope scope = buildSpan(exchange, props)) {
    AMQP.BasicProperties properties = inject(props, scope.span());
    channel.basicPublish(exchange, routingKey, mandatory, immediate, properties, body);
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:10,代码来源:TracingChannel.java

示例12: buildSpan

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
private Scope buildSpan(String exchange, AMQP.BasicProperties props) {
  Tracer.SpanBuilder spanBuilder = tracer.buildSpan("send")
      .ignoreActiveSpan()
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER);

  SpanContext spanContext = null;

  if (props != null && props.getHeaders() != null) {
    // just in case if span context was injected manually to props in basicPublish
    spanContext = tracer.extract(Format.Builtin.TEXT_MAP,
        new HeadersMapExtractAdapter(props.getHeaders()));
  }

  if (spanContext == null) {
    Span parentSpan = tracer.activeSpan();
    if (parentSpan != null) {
      spanContext = parentSpan.context();
    }
  }

  if (spanContext != null) {
    spanBuilder.asChildOf(spanContext);
  }

  Scope scope = spanBuilder.startActive(true);
  SpanDecorator.onRequest(exchange, scope.span());

  return scope;
}
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:30,代码来源:TracingChannel.java

示例13: basicUsage

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
@Test
public void basicUsage() throws IOException, InterruptedException {
    AutorecoverableQueueingConsumer consumer = new AutorecoverableQueueingConsumer(null);
    Envelope envelope = new Envelope(0, true, null, null);
    AMQP.BasicProperties properties = new AMQP.BasicProperties();
    byte[] messageBody = "messageBody".getBytes();
    consumer.handleDelivery(null, envelope, properties, messageBody);
    RabbitMqMessage message1 = consumer.nextMessage(100);
    assertEquals(envelope, message1.getEnvelope());
    assertEquals(properties, message1.getProperties());
    assertArrayEquals(messageBody, message1.getBody());
    RabbitMqMessage message2 = consumer.nextMessage(100);
    assertNull(message2);
}
 
开发者ID:anderelate,项目名称:storm-rabbitmq,代码行数:15,代码来源:AutorecoverableQueueingConsumerTest.java

示例14: reply

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
public int reply(JSONObject message){ 
	/*Used when a request has already been listened 
	through this object and then if you want to revert for that  request*/
	try{
		String routingKey = replyMqName;
		AMQP.BasicProperties props = new AMQP.BasicProperties();
		channel.basicPublish(defaultExchange, routingKey, props, message.toString().getBytes("UTF-8"));
	}
	catch(Exception e){
		e.printStackTrace();
		return 0;
	}
	return 1;
}
 
开发者ID:hemantverma1,项目名称:ServerlessPlatform,代码行数:15,代码来源:communicateWithMQ.java

示例15: defaultStreamId

import com.rabbitmq.client.AMQP; //导入方法依赖的package包/类
@Test
public void defaultStreamId() throws Exception {
    RabbitMqMessageScheme rabbitMqMessageScheme = new SingleStreamRabbitMqMessageScheme() {
        @Override
        public void prepare(Map config, TopologyContext context) {
            // no operation
        }
        
        @Override
        public List<Object> convertToTuple(Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws Exception {
            return Arrays.asList("stringValue");
        }

        @Override
        public Fields getOutputFields() {
            return new Fields("stringField");
        }

        @Override
        public void cleanup() {
            // no operation
        }
    };

    StreamedTuple streamedTuple = rabbitMqMessageScheme.convertToStreamedTuple(null, null, null);
    assertEquals(Utils.DEFAULT_STREAM_ID, streamedTuple.getStreamId());
}
 
开发者ID:anderelate,项目名称:storm-rabbitmq,代码行数:28,代码来源:SingleStreamRabbitMqMessageSchemeTest.java


注:本文中的com.rabbitmq.client.AMQP.BasicProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。