本文整理匯總了Java中com.rabbitmq.client.AMQP.BasicProperties類的典型用法代碼示例。如果您正苦於以下問題:Java BasicProperties類的具體用法?Java BasicProperties怎麽用?Java BasicProperties使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BasicProperties類屬於com.rabbitmq.client.AMQP包,在下文中一共展示了BasicProperties類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setVirtualHost("/");
factory.setHost("localhost");
factory.setPort(5672);
Connection newConnection = factory.newConnection();
Channel channel = newConnection.createChannel();
Scanner scanner = new Scanner(System.in);
String message = "";
while(!message.equals("exit")){
System.out.println("Enter your message");
message = scanner.next();
channel.queueDeclare("flink-test", true, false, false, null);
channel.basicPublish("", "flink-test", new BasicProperties.Builder()
.correlationId(java.util.UUID.randomUUID().toString()).build(), message.getBytes());
}
scanner.close();
channel.close();
newConnection.close();
}
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:26,代碼來源:RMQPublisher.java
示例2: main
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
/**
* @param args
* @throws TimeoutException
* @throws IOException
* @throws InterruptedException
* @throws ConsumerCancelledException
* @throws ShutdownSignalException
*/
public static void main(String[] args) throws IOException, TimeoutException, ShutdownSignalException,
ConsumerCancelledException, InterruptedException {
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.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
channel.basicQos(1);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(RPC_QUEUE_NAME, false, consumer);
System.out.println("RPCServer Awating RPC request");
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
BasicProperties props = delivery.getProperties();
BasicProperties replyProps = new AMQP.BasicProperties.Builder().correlationId(props.getCorrelationId())
.build();
String message = new String(delivery.getBody(), "UTF-8");
int n = Integer.parseInt(message);
System.out.println("RPCServer fib(" + message + ")");
String response = "" + fib(n);
channel.basicPublish("", props.getReplyTo(), replyProps, response.getBytes());
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
}
示例3: handleDelivery
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
@Override
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {
if(body != null) {
try {
// resolve the returned message
long deliveryTag = envelope.getDeliveryTag();
String message = new String(body, "UTF-8");
LOG.info("Task received: consumerTag=" + consumerTag + ", deliveryTag=" + deliveryTag + ", message=" + message);
JSONObject taskReq = JSONObject.parseObject(message);
if(!taskReq.isEmpty()) {
long id = messageIdGenerator.incrementAndGet();
WaitingTask task = new WaitingTask(id, taskReq, getChannel(), deliveryTag);
waitingTasks.putLast(task);
LOG.info("Add task to waiting queue: " + task);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例4: send
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
/****
* This method is used to publish the message to RabbitMQ
* @param routingKey
* @param msg is Eiffel Event
* @throws IOException
*/
public void send(String routingKey, String msg) throws IOException {
Channel channel = giveMeRandomChannel();
channel.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
// Beware that proper synchronization is needed here
if (cause.isInitiatedByApplication()) {
log.debug("Shutdown is initiated by application. Ignoring it.");
} else {
log.error("Shutdown is NOT initiated by application.");
log.error(cause.getMessage());
boolean cliMode = Boolean.getBoolean(PropertiesConfig.CLI_MODE);
if (cliMode) {
System.exit(-3);
}
}
}
});
BasicProperties msgProps = MessageProperties.BASIC;
if (usePersitance)
msgProps = MessageProperties.PERSISTENT_BASIC;
channel.basicPublish(exchangeName, routingKey, msgProps, msg.getBytes());
log.info("Published message with size {} bytes on exchange '{}' with routing key '{}'", msg.getBytes().length,
exchangeName, routingKey);
}
示例5: call
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
public String call(String message) throws Exception {
String response = null;
String corrId = UUID.randomUUID().toString();
BasicProperties props = new BasicProperties.Builder().correlationId(corrId).replyTo(replyQueueName).build();
channel.basicPublish("", requestQueueName, props, message.getBytes("UTF-8"));
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = new String(delivery.getBody(), "UTF-8");
break;
}
}
return response;
}
示例6: sendToCmdQueue
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
/**
* Sends the given command to the command queue with the given data appended
* and using the given properties.
*
* @param address
* address for the message
* @param command
* the command that should be sent
* @param data
* data that should be appended to the command
* @param props
* properties that should be used for the message
* @throws IOException
*/
protected void sendToCmdQueue(String address, byte command, byte data[], BasicProperties props) throws IOException {
byte sessionIdBytes[] = RabbitMQUtils.writeString(address);
// + 5 because 4 bytes for the session ID length and 1 byte for the
// command
int dataLength = sessionIdBytes.length + 5;
boolean attachData = (data != null) && (data.length > 0);
if (attachData) {
dataLength += data.length;
}
ByteBuffer buffer = ByteBuffer.allocate(dataLength);
buffer.putInt(sessionIdBytes.length);
buffer.put(sessionIdBytes);
buffer.put(command);
if (attachData) {
buffer.put(data);
}
cmdChannel.basicPublish(Constants.HOBBIT_COMMAND_EXCHANGE_NAME, "", props, buffer.array());
}
示例7: call
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
public String call(String message) throws Exception {
String response;
String corrId = UUID.randomUUID().toString();
BasicProperties props = new BasicProperties
.Builder()
.correlationId(corrId)
.replyTo(replyQueueName)
.build();
channel.basicPublish("", requestQueueName, props, message.getBytes("UTF-8"));
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = new String(delivery.getBody(), "UTF-8");
break;
}
}
return response;
}
示例8: call
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
public String call(String message) throws Exception {
String response = null;
String corrId = UUID.randomUUID().toString();
BasicProperties props = new BasicProperties.Builder().correlationId(corrId).replyTo(replyQueueName).build();
channel.basicPublish("", requestQueueName, props, message.getBytes("UTF-8"));
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = new String(delivery.getBody(), "UTF-8");
break;
}
}
return response;
}
示例9: call
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
public byte[] call(String methodName, String message) throws Exception {
byte[] response = null;
String corrId = UUID.randomUUID().toString();
BasicProperties props = new BasicProperties
.Builder()
.correlationId(corrId)
.replyTo(replyQueueName)
.build();
channel.basicPublish("", REQUEST_QUEUE_NAME, props, message.getBytes("UTF-8"));
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = delivery.getBody();
break;
}
}
return response;
}
示例10: consume
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
private void consume(final String consumerTag, final Envelope envelope, final BasicProperties properties,
final byte[] body) {
final Message rawMessage = Message.builder()
.body(body)
.contentType(properties.getContentType())
.encoding(properties.getContentEncoding())
.type(properties.getType())
.build();
final T message = deserialize(rawMessage);
final Consumer<Void> onAck = ackAction(envelope.getDeliveryTag());
final MessageContext<T> messageContext = new RabbitMessageContext<>(
message, consumerTag, envelope.getExchange(), envelope.getRoutingKey(),
properties, onAck);
logDelivery(messageContext);
consumer.accept(messageContext);
}
示例11: testConnectionFactory
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
@Test
public void testConnectionFactory() throws Exception {
Assert.assertNotNull(connectionFactory1);
Assert.assertNotNull(queue);
RabbitmqConnection connection = connectionFactory1.getConnection();
Assert.assertNotNull(connection);
String queueName = "testing";
Channel channel = connection.createChannel();
channel.queueDeclare(queueName, false, false, false, null);
String message = "Hello World!";
final CountDownLatch counter = new CountDownLatch(1);
Consumer consume = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
BasicProperties properties, byte[] body) throws IOException {
Assert.assertEquals("Hello World!", new String(body));
counter.countDown();
}
};
channel.basicConsume(queueName, true, consume);
channel.basicPublish("", queueName, null, message.getBytes());
counter.await(10, TimeUnit.SECONDS);
Assert.assertEquals(0, counter.getCount());
channel.close();
}
示例12: setup
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
public void setup() throws Exception {
if (log.isTraceEnabled()) {
log.trace("setup()");
}
this.consumer = new DefaultConsumer(this.channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
BasicProperties properties, byte[] body) throws IOException {
MessageEndpoint localEndpoint;
try {
localEndpoint = endpointFactory.createEndpoint(null);
RabbitmqBytesMessage m = new RabbitmqBytesMessage(consumerTag,envelope,properties,body);
onMessage(localEndpoint, m);
} catch (UnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
if ("javax.jms.Queue".equals(this.spec.getDestinationType())) {
RabbitmqAdminQueueImpl queue = Util.lookup(new InitialContext(), this.spec.getDestination(), RabbitmqAdminQueueImpl.class);
this.channel.basicConsume(queue.getDestinationAddress(),true, consumer);
}
}
示例13: handleDelivery
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
/**
* Handles a message delivery from the broker.
*/
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
BasicProperties properties, byte[] body) throws IOException {
LOG.debug("Consumer: {} Received handle delivery", consumerTag);
Message message = new Message(properties, body, envelope.getExchange(),
envelope.getRoutingKey(), envelope.getDeliveryTag());
LOG.info("Consumer: {} Received message: {}", consumerTag,
envelope.getDeliveryTag());
handleMessage(message);
_channel.basicAck(envelope.getDeliveryTag(), true);
}
示例14: valueOf
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
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;
}
示例15: rpcCall
import com.rabbitmq.client.AMQP.BasicProperties; //導入依賴的package包/類
private String rpcCall(String message) throws Exception {
String QUEUE_NAME = "TEST_RPC";
String replyQueueName = channel.queueDeclare().getQueue();
System.out.println("replyQueueName: " + replyQueueName);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(replyQueueName, true, consumer);
String response = null;
String corrId = java.util.UUID.randomUUID().toString();
BasicProperties props = new BasicProperties.Builder()
.correlationId(corrId).replyTo(replyQueueName).build();
channel.basicPublish("", QUEUE_NAME, props, message.getBytes());
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
if (delivery.getProperties().getCorrelationId().equals(corrId)) {
response = new String(delivery.getBody());
break;
}
}
return response;
}