public void testSSL() throws IOException { channel.queueDeclare("Bug19356Test", false, true, true, null); channel.basicPublish("", "Bug19356Test", null, "SSL".getBytes()); GetResponse chResponse = channel.basicGet("Bug19356Test", false); assertNotNull(chResponse); byte[] body = chResponse.getBody(); assertEquals("SSL", new String(body)); }
/* Publish a message of size FRAME_MAX. The broker should split * this into two frames before sending back. Frame content should * be less or equal to frame-max - 8. */ public void testFrameSizes() throws IOException, InterruptedException { String queueName = channel.queueDeclare().getQueue(); /* This should result in at least 3 frames. */ int howMuch = 2 * FRAME_MAX; basicPublishVolatile(new byte[howMuch], queueName); /* Receive everything that was sent out. */ while (howMuch > 0) { try { GetResponse response = channel.basicGet(queueName, false); howMuch -= response.getBody().length; } catch (Exception e) { e.printStackTrace(); fail("Exception in basicGet loop: " + e); } } }
@Override public PollableSource.Status process() throws EventDeliveryException { if (null == _Connection) { try { if (log.isInfoEnabled()) log.info( this.getName() + " - Opening connection to " + _ConnectionFactory.getHost() + ":" + _ConnectionFactory.getPort()); _Connection = _ConnectionFactory.newConnection(); _CounterGroup.incrementAndGet(RabbitMQConstants.COUNTER_NEW_CONNECTION); _Channel = null; } catch (Exception ex) { if (log.isErrorEnabled()) log.error(this.getName() + " - Exception while establishing connection.", ex); resetConnection(); return Status.BACKOFF; } } if (null == _Channel) { try { if (log.isInfoEnabled()) log.info(this.getName() + " - creating channel..."); _Channel = _Connection.createChannel(); _CounterGroup.incrementAndGet(RabbitMQConstants.COUNTER_NEW_CHANNEL); if (log.isInfoEnabled()) log.info( this.getName() + " - Connected to " + _ConnectionFactory.getHost() + ":" + _ConnectionFactory.getPort()); if (StringUtils.isNotEmpty(_ExchangeName)) { try { // declare an exchange _Channel.exchangeDeclarePassive(_ExchangeName); // only grab a default queuename if one is not specified in config if (StringUtils.isEmpty(_QueueName)) { _QueueName = _Channel.queueDeclare().getQueue(); } // for each topic, bind to the key if (null != _Topics) { for (String topic : _Topics) { _Channel.queueBind(_QueueName, _ExchangeName, topic); } } } catch (Exception ex) { if (log.isErrorEnabled()) log.error(this.getName() + " - Exception while declaring exchange.", ex); resetConnection(); return Status.BACKOFF; } } } catch (Exception ex) { if (log.isErrorEnabled()) log.error(this.getName() + " - Exception while creating channel.", ex); resetConnection(); return Status.BACKOFF; } } GetResponse response; try { response = _Channel.basicGet(_QueueName, false); _CounterGroup.incrementAndGet(RabbitMQConstants.COUNTER_GET); } catch (Exception ex) { _CounterGroup.incrementAndGet(RabbitMQConstants.COUNTER_EXCEPTION); if (log.isErrorEnabled()) log.error(this.getName() + " - Exception thrown while pulling from queue.", ex); resetConnection(); return Status.BACKOFF; } if (null == response) { _CounterGroup.incrementAndGet(RabbitMQConstants.COUNTER_GET_MISS); return Status.BACKOFF; } try { Map<String, String> properties = RabbitMQUtil.getHeaders(response.getProps()); Event event = new SimpleEvent(); event.setBody(response.getBody()); event.setHeaders(properties); getChannelProcessor().processEvent(event); } catch (Exception ex) { if (log.isErrorEnabled()) log.error(this.getName() + " - Exception thrown while processing event", ex); return Status.BACKOFF; } try { _Channel.basicAck(response.getEnvelope().getDeliveryTag(), false); _CounterGroup.incrementAndGet(RabbitMQConstants.COUNTER_ACK); } catch (Exception ex) { _CounterGroup.incrementAndGet(RabbitMQConstants.COUNTER_EXCEPTION); if (log.isErrorEnabled()) log.error(this.getName() + " - Exception thrown while sending ack to queue", ex); resetConnection(); return Status.BACKOFF; } return Status.READY; }