本文整理匯總了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);
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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()
);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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());
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}