List of usage examples for com.rabbitmq.client Channel close
@Override void close() throws IOException, TimeoutException;
From source file:org.axonframework.amqp.eventhandling.RabbitMQBenchmark.java
License:Apache License
private static List<Thread> createChannelCreatingThreads(final Connection connection, final String queueName, final boolean transactional) { List<Thread> threads = new ArrayList<>(); for (int i = 0; i < THREAD_COUNT; i++) { threads.add(new Thread(() -> { try { for (int t = 0; t < COMMIT_COUNT; t++) { final Channel localChannel = connection.createChannel(); if (transactional) { localChannel.txSelect(); }/*from ww w. java2s .c om*/ for (int j = 0; j < COMMIT_SIZE; j++) { localChannel.basicPublish("", queueName, null, ("message" + t).getBytes("UTF-8")); } if (transactional) { localChannel.txCommit(); } localChannel.close(); } } catch (IOException | TimeoutException e) { e.printStackTrace(); } })); } return threads; }
From source file:org.axonframework.amqp.eventhandling.RabbitMQBenchmark.java
License:Apache License
private static List<Thread> createChannelPoolSharingThreads(final Connection connection, final String queueName) { List<Thread> threads = new ArrayList<>(); final Queue<Channel> channels = new ArrayBlockingQueue<>(15); for (int i = 0; i < THREAD_COUNT; i++) { threads.add(new Thread(() -> { try { for (int t = 0; t < COMMIT_COUNT; t++) { Channel localChannel = channels.poll(); if (localChannel == null) { localChannel = connection.createChannel(); }//from w w w. j a v a2 s.c o m localChannel.txSelect(); for (int j = 0; j < COMMIT_SIZE; j++) { localChannel.basicPublish("", queueName, null, ("message" + t).getBytes("UTF-8")); } localChannel.txCommit(); if (!channels.offer(localChannel)) { localChannel.close(); } } } catch (IOException | TimeoutException e) { e.printStackTrace(); } })); } return threads; }
From source file:org.axonframework.amqp.eventhandling.spring.SpringAMQPPublisher.java
License:Apache License
private void tryClose(Channel channel) { try {// w w w . j a v a2 s . c o m channel.close(); } catch (IOException | TimeoutException e) { logger.info("Unable to close channel. It might already be closed.", e); } }
From source file:org.axonframework.eventhandling.amqp.RabbitMQBenchmark.java
License:Apache License
private static List<Thread> createChannelCreatingThreads(final Connection connection, final String queueName, final boolean transactional) { List<Thread> threads = new ArrayList<Thread>(); for (int i = 0; i < THREAD_COUNT; i++) { threads.add(new Thread(new Runnable() { @Override// ww w .j av a 2 s . com public void run() { try { for (int t = 0; t < COMMIT_COUNT; t++) { final Channel localChannel = connection.createChannel(); if (transactional) { localChannel.txSelect(); } for (int j = 0; j < COMMIT_SIZE; j++) { localChannel.basicPublish("", queueName, null, ("message" + t).getBytes("UTF-8")); } if (transactional) { localChannel.txCommit(); } localChannel.close(); } } catch (IOException e) { e.printStackTrace(); } } })); } return threads; }
From source file:org.axonframework.eventhandling.amqp.RabbitMQBenchmark.java
License:Apache License
private static List<Thread> createChannelPoolSharingThreads(final Connection connection, final String queueName) { List<Thread> threads = new ArrayList<Thread>(); final Queue<Channel> channels = new ArrayBlockingQueue<Channel>(15); for (int i = 0; i < THREAD_COUNT; i++) { threads.add(new Thread(new Runnable() { @Override/* w w w . j ava 2 s. c o m*/ public void run() { try { for (int t = 0; t < COMMIT_COUNT; t++) { Channel localChannel = channels.poll(); if (localChannel == null) { localChannel = connection.createChannel(); } localChannel.txSelect(); for (int j = 0; j < COMMIT_SIZE; j++) { localChannel.basicPublish("", queueName, null, ("message" + t).getBytes("UTF-8")); } localChannel.txCommit(); if (!channels.offer(localChannel)) { localChannel.close(); } } } catch (IOException e) { e.printStackTrace(); } } })); } return threads; }
From source file:org.axonframework.eventhandling.amqp.spring.AMQPTerminalTest.java
License:Apache License
@Before public void setUp() throws Exception { try {/*from w w w . j a v a2 s .co m*/ Channel channel = connectionFactory.createConnection().createChannel(false); if (channel.isOpen()) { channel.close(); } } catch (Exception e) { assumeNoException(e); } }
From source file:org.axonframework.eventhandling.amqp.spring.SpringAMQPEventBus.java
License:Apache License
private void tryClose(Channel channel) { try {/*from w w w. jav a 2s. c o m*/ channel.close(); } catch (IOException e) { logger.info("Unable to close channel. It might already be closed.", e); } }
From source file:org.axonframework.eventhandling.amqp.spring.SpringAMQPEventBusIntegrationTest.java
License:Apache License
@Before public void setUp() throws Exception { try {/* w ww . j a va 2 s .c o m*/ Channel channel = connectionFactory.createConnection().createChannel(false); if (channel.isOpen()) { channel.close(); } } catch (Exception e) { assumeNoException(e); } eventBus.subscribe(eventProcessor); }
From source file:org.axonframework.eventhandling.amqp.spring.SpringAMQPTerminalIntegrationTest.java
License:Apache License
@Before public void setUp() throws Exception { try {/*from w w w . j a va2 s .co m*/ Channel channel = connectionFactory.createConnection().createChannel(false); if (channel.isOpen()) { channel.close(); } } catch (Exception e) { assumeNoException(e); } // eventBus.subscribe(eventProcessor); }
From source file:org.ballerinalang.messaging.rabbitmq.nativeimpl.channel.listener.Stop.java
License:Open Source License
@Override public void execute(Context context) { @SuppressWarnings(RabbitMQConstants.UNCHECKED) BMap<String, BValue> channelListObject = (BMap<String, BValue>) context.getRefArgument(0); @SuppressWarnings(RabbitMQConstants.UNCHECKED) BMap<String, BValue> channelOb = (BMap<String, BValue>) channelListObject .get(RabbitMQConstants.CHANNEL_REFERENCE); Channel channel = (Channel) channelOb.getNativeData(RabbitMQConstants.CHANNEL_NATIVE_OBJECT); if (channel == null) { throw new BallerinaException("ChannelListener not properly initialised"); } else {//w w w . j av a 2 s . c om try { Connection connection = channel.getConnection(); channel.close(); connection.close(); } catch (IOException | TimeoutException exception) { RabbitMQUtils.returnError(RabbitMQConstants.CLOSE_CHANNEL_ERROR + " " + exception.getMessage(), context, exception); } } }