Example usage for com.rabbitmq.client Channel basicQos

List of usage examples for com.rabbitmq.client Channel basicQos

Introduction

In this page you can find the example usage for com.rabbitmq.client Channel basicQos.

Prototype

void basicQos(int prefetchSize, int prefetchCount, boolean global) throws IOException;

Source Link

Document

Request specific "quality of service" settings.

Usage

From source file:com.nxttxn.vramel.components.rabbitMQ.RabbitMQConsumer.java

License:Apache License

/**
 * Open channel//w  w  w . java2s  . c  o m
 */
private Channel openChannel() throws IOException {
    logger.trace("Creating channel...");
    Channel channel = conn.createChannel();
    logger.debug("Created channel: {}", channel);
    // setup the basicQos
    if (endpoint.isPrefetchEnabled()) {
        channel.basicQos(endpoint.getPrefetchSize(), endpoint.getPrefetchCount(), endpoint.isPrefetchGlobal());
    }
    return channel;
}

From source file:org.apache.camel.component.rabbitmq.reply.TemporaryQueueReplyManager.java

License:Apache License

@Override
protected Connection createListenerContainer() throws Exception {

    log.debug("Creating connection");
    Connection conn = endpoint.connect(executorService);

    log.debug("Creating channel");
    Channel channel = conn.createChannel();
    // setup the basicQos
    if (endpoint.isPrefetchEnabled()) {
        channel.basicQos(endpoint.getPrefetchSize(), endpoint.getPrefetchCount(), endpoint.isPrefetchGlobal());
    }/*from   w  w w  .j  a v  a 2 s  .  com*/

    //Let the server pick a random name for us
    DeclareOk result = channel.queueDeclare();
    log.debug("Temporary queue name {}", result.getQueue());
    setReplyTo(result.getQueue());

    //TODO check for the RabbitMQConstants.EXCHANGE_NAME header 
    channel.queueBind(getReplyTo(), endpoint.getExchangeName(), getReplyTo());

    consumer = new RabbitConsumer(this, channel);
    consumer.start();

    return conn;
}

From source file:org.ballerinalang.messaging.rabbitmq.nativeimpl.channel.listener.SetQosSettings.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> channelObj = (BMap<String, BValue>) channelListObject
            .get(RabbitMQConstants.CHANNEL_REFERENCE);
    Channel channel = (Channel) channelObj.getNativeData(RabbitMQConstants.CHANNEL_NATIVE_OBJECT);
    BValue prefetchCount = context.getNullableRefArgument(1);
    boolean isValidCount = prefetchCount instanceof BInteger;
    try {/*from ww  w.j a v  a  2s.  c o m*/
        if (isValidCount) {
            BValue prefetchSize = context.getNullableRefArgument(2);
            boolean isValidSize = prefetchSize instanceof BInteger;
            if (isValidSize) {
                channel.basicQos(Math.toIntExact(((BInteger) prefetchSize).intValue()),
                        Math.toIntExact(((BInteger) prefetchCount).intValue()), true);
                channelObj.addNativeData(RabbitMQConstants.QOS_STATUS, true);
            } else {
                channel.basicQos(Math.toIntExact(((BInteger) prefetchCount).intValue()), true);
                channelObj.addNativeData(RabbitMQConstants.QOS_STATUS, true);
            }
        }
    } catch (IOException exception) {
        RabbitMQUtils.returnError(
                "I/O error occurred while setting the global " + "quality of service settings for the listener",
                context, exception);
    }
}

From source file:org.ballerinalang.messaging.rabbitmq.nativeimpl.channel.listener.Start.java

License:Open Source License

/**
 * Request specific "quality of service" settings.
 *
 * @param channel         RabbitMQ Channel object.
 * @param annotationValue Struct value of the Annotation.
 *///from   w  ww. j a  v  a  2  s .  c o  m
private static void handleBasicQos(Channel channel, Struct annotationValue) {
    long prefetchCount = RabbitMQConstants.DEFAULT_PREFETCH;
    if (annotationValue.getRefField(RabbitMQConstants.PREFETCH_COUNT) != null) {
        prefetchCount = annotationValue.getIntField(RabbitMQConstants.PREFETCH_COUNT);
    }
    boolean isValidPrefetchSize = annotationValue.getRefField(RabbitMQConstants.PREFETCH_SIZE) != null;
    try {
        if (isValidPrefetchSize) {
            channel.basicQos(Math.toIntExact(annotationValue.getIntField(RabbitMQConstants.PREFETCH_SIZE)),
                    Math.toIntExact(prefetchCount),
                    annotationValue.getBooleanField(RabbitMQConstants.PREFETCH_GLOBAL));
        } else {
            channel.basicQos(Math.toIntExact(prefetchCount));
        }
    } catch (IOException | ArithmeticException exception) {
        String errorMessage = "An error occurred while setting the basic quality of service settings ";
        throw new RabbitMQConnectorException(errorMessage + exception.getMessage(), exception);
    }
}

From source file:org.mule.transport.amqp.internal.client.ChannelHandler.java

License:Open Source License

public Channel createChannel(ImmutableEndpoint endpoint) throws IOException {
    final AmqpConnector connector = (AmqpConnector) endpoint.getConnector();

    try {/*from  w w  w .ja va2s .c  o m*/
        final Channel channel = connector.getConnection().createChannel();
        channel.addReturnListener(connector.getDefaultReturnListener());
        channel.basicQos(connector.getPrefetchSize(), connector.getPrefetchCount(), false);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Created and configured new channel: " + channel);
        }

        channel.addShutdownListener(new ShutdownListener() {
            public void shutdownCompleted(final ShutdownSignalException sse) {
                if (sse.isInitiatedByApplication()) {
                    return;
                }

                // do not inform the connector of the issue as it can't
                // decide what to do reset the channel so it would later
                // be lazily reconnected
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Terminated dead channel: " + channel, sse);
                }
            }
        });

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Shutdown listener configured on channel: " + channel);
        }

        return channel;
    } catch (final Exception e) {
        if ((!connector.isStopping()) && (connector.isStarted())) {
            connector.getMuleContext().getExceptionListener()
                    .handleException(new ConnectException(MessageFactory.createStaticMessage(
                            "Impossible to create new channels on connection: " + connector.getConnection()), e,
                            connector));
        }
        return null;
    }

}