use of com.rabbitmq.client.BasicProperties in project LinkAgent by shulieTech.
the class ChannelNProcessDeliveryInterceptor method beforeFirst.
@Override
public void beforeFirst(Advice advice) {
Object[] args = advice.getParameterArray();
String methodName = advice.getBehaviorName();
if (!PradarSwitcher.isClusterTestEnabled()) {
logger.warn("PradarSwitcher isClusterTestEnabled false, {} to start shadow {} skip it", advice.getTargetClass().getName(), methodName);
return;
}
AMQP.Basic.Deliver m = (AMQP.Basic.Deliver) args[1];
validatePressureMeasurement(m.getConsumerTag());
try {
Command command = (Command) args[0];
BasicProperties contentHeader = (BasicProperties) command.getContentHeader();
Map<String, Object> headers = contentHeader.getHeaders();
if (null != headers && headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY) != null && ClusterTestUtils.isClusterTestRequest(headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY).toString())) {
Pradar.setClusterTest(true);
}
if (!Pradar.isClusterTest()) {
String routingKey = m.getRoutingKey();
if (StringUtils.isNotBlank(routingKey) && ClusterTestUtils.isClusterTestRequest(routingKey)) {
Pradar.setClusterTest(true);
}
String exchange = m.getExchange();
if (StringUtils.isNotBlank(exchange) && ClusterTestUtils.isClusterTestRequest(exchange)) {
Pradar.setClusterTest(true);
}
}
} catch (Throwable e) {
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
}
}
use of com.rabbitmq.client.BasicProperties in project rabbitmq-jms-client by rabbitmq.
the class RMQMessage method convertAmqpMessage.
private static RMQMessage convertAmqpMessage(RMQSession session, RMQDestination dest, GetResponse response) throws JMSException {
try {
BasicProperties props = response.getProps();
RMQMessage message = RMQMessage.isAmqpTextMessage(props.getHeaders()) ? new RMQTextMessage() : new RMQBytesMessage();
// Deserialize the message payload from the byte[] body
message = RMQMessage.fromAmqpMessage(response.getBody(), message);
// Insert session in received message for Message.acknowledge
message.setSession(session);
// Set the redelivered flag
message.setJMSRedelivered(response.getEnvelope().isRedeliver());
// Insert delivery tag in received message for Message.acknowledge
message.setRabbitDeliveryTag(response.getEnvelope().getDeliveryTag());
// We cannot know the original destination, so set local one
message.setJMSDestination(dest);
message.setJMSPropertiesFromAmqpProperties(props);
// Set readOnly - mandatory for received messages
message.setReadonly(true);
return message;
} catch (IOException x) {
throw new RMQJMSException(x);
}
}
use of com.rabbitmq.client.BasicProperties in project rabbitmq-jms-client by rabbitmq.
the class RMQMessage method convertAmqpMessage.
private static RMQMessage convertAmqpMessage(RMQSession session, RMQDestination dest, GetResponse response, ReceivingContextConsumer receivingContextConsumer) throws JMSException {
try {
BasicProperties props = response.getProps();
RMQMessage message = RMQMessage.isAmqpTextMessage(props.getHeaders()) ? new RMQTextMessage() : new RMQBytesMessage();
// Deserialize the message payload from the byte[] body
message = RMQMessage.fromAmqpMessage(response.getBody(), message);
// Insert session in received message for Message.acknowledge
message.setSession(session);
// Set the redelivered flag
message.setJMSRedelivered(response.getEnvelope().isRedeliver());
// Insert delivery tag in received message for Message.acknowledge
message.setRabbitDeliveryTag(response.getEnvelope().getDeliveryTag());
// We cannot know the original destination, so set local one
message.setJMSDestination(dest);
message.setJMSPropertiesFromAmqpProperties(props);
// Set readOnly - mandatory for received messages
message.setReadonly(true);
maybeSetupDirectReplyTo(message, response.getProps().getReplyTo());
receivingContextConsumer.accept(new ReceivingContext(message));
return message;
} catch (IOException x) {
throw new RMQJMSException(x);
}
}
use of com.rabbitmq.client.BasicProperties in project LinkAgent by shulieTech.
the class ChannelNProcessDeliveryInterceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
if (ConfigCache.isWorkWithSpring()) {
return null;
}
Object[] args = advice.getParameterArray();
Command command = (Command) args[0];
Deliver method = (Deliver) args[1];
SpanRecord record = new SpanRecord();
record.setService(method.getExchange());
record.setMethod(method.getRoutingKey());
BasicProperties contentHeader = (BasicProperties) command.getContentHeader();
Map<String, Object> headers = contentHeader.getHeaders();
if (headers != null) {
Map<String, String> rpcContext = new HashMap<String, String>();
for (String key : Pradar.getInvokeContextTransformKeys()) {
String value = ObjectUtils.toString(headers.get(key));
if (!StringUtil.isEmpty(value)) {
rpcContext.put(key, value);
}
}
record.setContext(rpcContext);
}
byte[] body = command.getContentBody();
record.setRequestSize(body.length);
record.setRequest(body);
Channel channel = (Channel) advice.getTarget();
Connection connection = channel.getConnection();
record.setRemoteIp(connection.getAddress().getHostAddress());
record.setPort(connection.getPort() + "");
return record;
}
use of com.rabbitmq.client.BasicProperties in project smallrye-reactive-messaging by smallrye.
the class RabbitMQUsage method produce.
/**
* Use the supplied function to asynchronously produce messages and write them to the host.
*
* @param exchange the exchange, must not be null
* @param messageCount the number of messages to produce; must be positive
* @param messageSupplier the function to produce messages; may not be null
*/
void produce(String exchange, String queue, String routingKey, int messageCount, Supplier<Object> messageSupplier) {
CountDownLatch done = new CountDownLatch(messageCount);
// Start the machinery to receive the messages
client.startAndAwait();
final Thread t = new Thread(() -> {
LOGGER.infof("Starting RabbitMQ sender to write %s messages with routing key %s", messageCount, routingKey);
try {
for (int i = 0; i != messageCount; ++i) {
final Object payload = messageSupplier.get();
final Buffer body = Buffer.buffer(payload.toString());
final BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").contentType("text/plain").build();
client.basicPublish(exchange, routingKey, properties, body).subscribe().with(v -> {
LOGGER.infof("Producer sent message %s", payload);
done.countDown();
}, Throwable::printStackTrace);
}
} catch (Exception e) {
LOGGER.error("Unable to send message", e);
}
LOGGER.infof("Finished sending %s messages with routing key %s", messageCount, routingKey);
});
t.setName(exchange + "-thread");
t.start();
try {
done.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// Ignore me
}
}
Aggregations