List of usage examples for com.rabbitmq.client MessageProperties PERSISTENT_BASIC
BasicProperties PERSISTENT_BASIC
To view the source code for com.rabbitmq.client MessageProperties PERSISTENT_BASIC.
Click Source Link
From source file:cc.gospy.core.remote.rabbitmq.RemoteScheduler.java
License:Apache License
@Override public void addTask(String executorId, Task task) { if (isSuspend.get()) { return;/*from w w w .ja v a2 s. co m*/ } try { channel.basicPublish("", NEW_TASK_QUEUE, MessageProperties.PERSISTENT_BASIC, SerializationUtils.serialize(task)); totalTaskInputCount.incrementAndGet(); } catch (IOException e) { e.printStackTrace(); } }
From source file:cc.gospy.core.remote.rabbitmq.RemoteScheduler.java
License:Apache License
@Override public void addLazyTask(String executorId, Task task) { if (isSuspend.get()) { return;/*from w w w .j a v a 2 s. co m*/ } try { channel.basicPublish("", NEW_LAZY_TASK_QUEUE, MessageProperties.PERSISTENT_BASIC, SerializationUtils.serialize(task)); totalTaskInputCount.incrementAndGet(); } catch (IOException e) { e.printStackTrace(); } }
From source file:cc.gospy.core.remote.rabbitmq.RemoteServiceProvider.java
License:Apache License
private void publish(Task task) throws IOException { AMQP.BasicProperties properties = !withPriority ? MessageProperties.PERSISTENT_BASIC : new AMQP.BasicProperties.Builder().contentType("application/octet-stream").deliveryMode(2) .priority((int) task.getPriority()).build(); channel.basicPublish(EXCHANGE, dispatcher.getTargetQueue(task), properties, SerializationUtils.serialize(task)); duplicateRemover.record(task);/*from www . jav a 2s . c om*/ }
From source file:com.ericsson.eiffel.remrem.publish.helper.RabbitMqProperties.java
License:Apache License
/** * This method is used to publish the message to RabbitMQ * @param routingKey//from w w w .ja v a 2 s.co m * @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); }
From source file:com.saasovation.common.port.adapter.messaging.rabbitmq.MessageProducer.java
License:Apache License
/** * Answers the binary durability BasicProperties according * to the brokerChannel's durability.// w w w .j a va 2 s .c o m * @return BasicProperties */ private BasicProperties binaryDurability() { BasicProperties durability = null; if (this.brokerChannel().isDurable()) { durability = MessageProperties.PERSISTENT_BASIC; } return durability; }
From source file:dk.au.cs.karibu.producer.rabbitmq.RabbitChannelConnector.java
License:Apache License
public void send(byte[] payload, String topic) throws IOException { channel.basicPublish(exchangeConfiguration.getExchangeName(), topic, MessageProperties.PERSISTENT_BASIC, payload);//from www.ja v a2 s . com }
From source file:joram.amqp.PersistenceKillTest.java
License:Open Source License
public void killingTest() throws Exception { senderConnection = new LiveServerConnection("sender", "localhost", 5672, null, null); receiverConnection = new LiveServerConnection("receiver", "localhost", 5672, null, null); senderConnection.startLiveConnection(); receiverConnection.startLiveConnection(); Channel senderChannel = senderConnection.getConnection().createChannel(); senderChannel.txSelect();// w w w . j a v a2 s .c o m DeclareOk declareOk = senderChannel.queueDeclare("testQueue", true, false, false, null); new Thread(new Runnable() { int received; long totalReceived; Channel consumerChannel; QueueingConsumer consumer; // Consumer thread public void run() { try { consumerChannel = receiverConnection.getConnection().createChannel(); consumerChannel.txSelect(); consumer = new QueueingConsumer(consumerChannel); consumerChannel.basicConsume("testQueue", false, consumer); } catch (Exception exc) { exc.printStackTrace(); } while (true) { QueueingConsumer.Delivery delivery; try { delivery = consumer.nextDelivery(); long receivedNb = Long.parseLong(new String(delivery.getBody())); consumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false); try { Thread.sleep(1); } catch (InterruptedException exc1) { } if (receivedNb < totalReceived) { System.out.println("Duplicate received: " + receivedNb); continue; } // We can receive duplicates but can't miss one message // One duplicate if the channel is transacted, multiple if it is not assertEquals(totalReceived, receivedNb); totalReceived++; received++; consumerChannel.txCommit(); if (received == nbMsgRound) { received = 0; synchronized (lock) { lock.notify(); } } if (totalReceived == nbMsgRound * nbRounds) { consumer.getChannel().close(); return; } } catch (Exception ie) { if (totalReceived == nbRounds * nbMsgRound) { return; } System.out.println("Consumer connection broken. Reconnect."); while (!receiverConnection.isConnectionOpen()) { try { Thread.sleep(100); } catch (InterruptedException exc) { exc.printStackTrace(); } } try { consumerChannel = receiverConnection.getConnection().createChannel(); consumerChannel.txSelect(); consumer = new QueueingConsumer(consumerChannel); consumerChannel.basicConsume("testQueue", false, consumer); } catch (IOException exc) { exc.printStackTrace(); } System.out.println("Consumer Reconnected --- totalReceived = " + totalReceived); continue; } } } }).start(); long start = System.nanoTime(); // Killer thread new Thread(new Runnable() { public void run() { try { Thread.sleep(5000); System.out.println("Kill server"); killAgentServer((short) 0); Thread.sleep(5000); startAgentServer((short) 0); System.out.println("server restarted."); } catch (Exception exc) { exc.printStackTrace(); } } }).start(); // Sender for (int i = 0; i < nbRounds; i++) { if (i % 20 == 0) { long delta = System.nanoTime() - start; System.out.println("Round " + i + " " + ((i * nbMsgRound * 1000000000L) / delta) + " msg/s"); } try { for (int j = 0; j < nbMsgRound; j++) { senderChannel.basicPublish("", declareOk.getQueue(), MessageProperties.PERSISTENT_BASIC, new Long(i * nbMsgRound + j).toString().getBytes()); } synchronized (lock) { senderChannel.txCommit(); lock.wait(); } } catch (Exception exc) { i--; System.out.println("Sender connection broken. Reconnect."); while (!senderConnection.isConnectionOpen()) { Thread.sleep(100); } senderChannel = senderConnection.getConnection().createChannel(); senderChannel.txSelect(); System.out.println("Sender Reconnected"); Thread.sleep(1000); System.out.println("Restart Sender"); } } long delta = System.nanoTime() - start; System.out.println(delta / 1000000L + " ms"); System.out.println(((nbRounds * nbMsgRound * 1000000000L) / delta) + " msg/s"); senderChannel.queueDelete(declareOk.getQueue()); senderChannel.close(); senderConnection.stopLiveConnection(); receiverConnection.stopLiveConnection(); }
From source file:joram.amqp.PersistenceSimpleTest.java
License:Open Source License
public void recover1() throws Exception { ConnectionFactory cnxFactory = new ConnectionFactory(); Connection connection = cnxFactory.newConnection(); Channel channel = connection.createChannel(); DeclareOk declareOk = channel.queueDeclare("testqueue", true, false, false, null); channel.txSelect();/* w w w . java2s . c o m*/ for (int i = 0; i < 5; i++) { channel.basicPublish("", declareOk.getQueue(), MessageProperties.PERSISTENT_BASIC, "this is a test message !!!".getBytes()); } channel.txCommit(); killAgentServer((short) 0); startAgentServer((short) 0); connection = cnxFactory.newConnection(); channel = connection.createChannel(); declareOk = channel.queueDeclarePassive("testqueue"); for (int i = 0; i < 5; i++) { GetResponse msg = channel.basicGet("testqueue", true); assertNotNull(msg); assertEquals("this is a test message !!!", new String(msg.getBody())); } GetResponse msg = channel.basicGet("testqueue", true); assertNull(msg); channel.queueDelete(declareOk.getQueue()); }
From source file:joram.amqp.PersistenceSimpleTest.java
License:Open Source License
public void recover2() throws Exception { ConnectionFactory cnxFactory = new ConnectionFactory(); Connection connection = cnxFactory.newConnection(); Channel channel = connection.createChannel(); DeclareOk declareOk = channel.queueDeclare("testqueue", true, false, false, null); channel.txSelect();/*from w w w.j a v a2s . c o m*/ for (int i = 0; i < 5; i++) { channel.basicPublish("", declareOk.getQueue(), MessageProperties.PERSISTENT_BASIC, "this is a test message !!!".getBytes()); } channel.txCommit(); killAgentServer((short) 0); startAgentServer((short) 0); Thread.sleep(500); connection = cnxFactory.newConnection(); channel = connection.createChannel(); declareOk = channel.queueDeclarePassive("testqueue"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(declareOk.getQueue(), true, consumer); for (int i = 0; i < 5; i++) { Delivery msg = consumer.nextDelivery(1000); assertNotNull(msg); assertEquals("this is a test message !!!", new String(msg.getBody())); } Delivery msg = consumer.nextDelivery(1000); assertNull(msg); channel.queueDelete(declareOk.getQueue()); }
From source file:mx.bigdata.utils.amqp.HaPublisher.java
License:Apache License
@Override public synchronized void publish(String exch, String routingKey, boolean mandatory, boolean immediate, AMQP.BasicProperties props, byte[] bytes) throws IOException { if (props == null) { props = MessageProperties.PERSISTENT_BASIC; }/* www . ja v a 2 s . co m*/ PublishWrapper msg = new PublishWrapper(exch, routingKey, mandatory, immediate, props, bytes); logger.trace("Publishing: " + msg); unconfirmedMap.put(getChannel().getNextPublishSeqNo(), msg); msg.publish(); //publish(exch, routingKey, mandatory, immediate, props, bytes); }