Example usage for com.rabbitmq.client ConnectionFactory setRequestedFrameMax

List of usage examples for com.rabbitmq.client ConnectionFactory setRequestedFrameMax

Introduction

In this page you can find the example usage for com.rabbitmq.client ConnectionFactory setRequestedFrameMax.

Prototype

public void setRequestedFrameMax(int requestedFrameMax) 

Source Link

Document

Set the requested maximum frame size

Usage

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

License:Apache License

private ConnectionFactory getOrCreateConnectionFactory() {
    if (connectionFactory == null) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername(getUsername());
        factory.setPassword(getPassword());
        factory.setVirtualHost(getVhost());
        factory.setHost(getHostname());/* w  w w.  ja v a  2 s .com*/
        factory.setPort(getPortNumber());
        if (getClientProperties() != null) {
            factory.setClientProperties(getClientProperties());
        }
        factory.setConnectionTimeout(getConnectionTimeout());
        factory.setRequestedChannelMax(getRequestedChannelMax());
        factory.setRequestedFrameMax(getRequestedFrameMax());
        factory.setRequestedHeartbeat(getRequestedHeartbeat());
        if (getSslProtocol() != null) {
            try {
                if (getSslProtocol().equals("true")) {
                    factory.useSslProtocol();
                } else if (getTrustManager() == null) {
                    factory.useSslProtocol(getSslProtocol());
                } else {
                    factory.useSslProtocol(getSslProtocol(), getTrustManager());
                }
            } catch (NoSuchAlgorithmException | KeyManagementException e) {
                throw new IllegalArgumentException("Invalid sslProtocol " + sslProtocol, e);
            }
        }
        if (getAutomaticRecoveryEnabled() != null) {
            factory.setAutomaticRecoveryEnabled(getAutomaticRecoveryEnabled());
        }
        if (getNetworkRecoveryInterval() != null) {
            factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval());
        }
        if (getTopologyRecoveryEnabled() != null) {
            factory.setTopologyRecoveryEnabled(getTopologyRecoveryEnabled());
        }
        connectionFactory = factory;
    }
    return connectionFactory;
}

From source file:io.bootique.rabbitmq.client.connection.ConnectionConfig.java

License:Apache License

public Connection createConnection(String connectionName) {
    com.rabbitmq.client.ConnectionFactory factory = createConnectionFactory();

    factory.setRequestedChannelMax(requestedChannelMax);
    factory.setRequestedFrameMax(requestedFrameMax);
    factory.setRequestedHeartbeat(requestedHeartbeat);
    factory.setConnectionTimeout(connectionTimeout);
    factory.setHandshakeTimeout(handshakeTimeout);
    factory.setShutdownTimeout(shutdownTimeout);
    factory.setAutomaticRecoveryEnabled(automaticRecoveryEnabled);
    factory.setTopologyRecoveryEnabled(topologyRecovery);
    factory.setNetworkRecoveryInterval(networkRecoveryInterval);

    LOGGER.info("Creating RabbitMQ connection.");
    try {/*from  www .java2s.  c o m*/
        return factory.newConnection();
    } catch (IOException | TimeoutException e) {
        throw new RuntimeException(String.format("Can't create connection \"%s\".", connectionName), e);
    }
}

From source file:org.apache.flink.streaming.connectors.rabbitmq.common.RMQConnectionConfig.java

License:Apache License

/**
 *
 * @return Connection Factory for RMQ/*  w  w w.  j ava2 s.  c o  m*/
 * @throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException if Malformed URI has been passed
 */
public ConnectionFactory getConnectionFactory()
        throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
    ConnectionFactory factory = new ConnectionFactory();
    if (this.uri != null && !this.uri.isEmpty()) {
        try {
            factory.setUri(this.uri);
        } catch (URISyntaxException | NoSuchAlgorithmException | KeyManagementException e) {
            LOG.error("Failed to parse uri", e);
            throw e;
        }
    } else {
        factory.setHost(this.host);
        factory.setPort(this.port);
        factory.setVirtualHost(this.virtualHost);
        factory.setUsername(this.username);
        factory.setPassword(this.password);
    }

    if (this.automaticRecovery != null) {
        factory.setAutomaticRecoveryEnabled(this.automaticRecovery);
    }
    if (this.connectionTimeout != null) {
        factory.setConnectionTimeout(this.connectionTimeout);
    }
    if (this.networkRecoveryInterval != null) {
        factory.setNetworkRecoveryInterval(this.networkRecoveryInterval);
    }
    if (this.requestedHeartbeat != null) {
        factory.setRequestedHeartbeat(this.requestedHeartbeat);
    }
    if (this.topologyRecovery != null) {
        factory.setTopologyRecoveryEnabled(this.topologyRecovery);
    }
    if (this.requestedChannelMax != null) {
        factory.setRequestedChannelMax(this.requestedChannelMax);
    }
    if (this.requestedFrameMax != null) {
        factory.setRequestedFrameMax(this.requestedFrameMax);
    }

    return factory;
}

From source file:org.kairosdb.plugin.rabbitmq.core.RabbitmqService.java

License:MIT License

@Override
public void start() throws KairosDBException {

    try {//from w  w  w. ja v a  2 s.  c o m
        LOGGER.info("[KRMQ] Starting to RabbitMQ consumer thread.");

        // Socket abstract connection with broker
        ConnectionFactory rabbitmqConnectionFactory = new ConnectionFactory();
        rabbitmqConnectionFactory.setHost(rabbmitmqHost);
        rabbitmqConnectionFactory.setVirtualHost(rabbitmqVirtualHost);
        rabbitmqConnectionFactory.setUsername(rabbitmqUser);
        rabbitmqConnectionFactory.setPassword(rabbitmqPassword);
        rabbitmqConnectionFactory.setPort(rabbitmqPort);
        rabbitmqConnectionFactory.setConnectionTimeout(rabbitmqTimeout);
        rabbitmqConnectionFactory.setRequestedChannelMax(rabbitmqChannelMax);
        rabbitmqConnectionFactory.setRequestedFrameMax(rabbitmqFrameMax);
        rabbitmqConnectionFactory.setRequestedHeartbeat(rabbitmqHearbeat);
        rabbitmqConnectionFactory.setAutomaticRecoveryEnabled(true);

        // Get KairosDatastore implementation
        KairosDatastore kairosDatabase = googleInjector.getInstance(KairosDatastore.class);

        // Create consumer thread
        RabbitmqConsumer consumer = new RabbitmqConsumer(kairosDatabase, rabbitmqConnectionFactory,
                bindingsFile, configurationJSONFieldValue, configurationJSONTimeStamp, configurationJSONTags,
                configurationCSVSeperator, configurationDefaultContentType);

        // Start consumer thread
        consumerThread = new Thread(consumer);
        consumerThread.start();

    } catch (Exception e) {
        LOGGER.error("[KRMQ] An error occurred: ", e);
    }
}

From source file:org.springframework.amqp.rabbit.MulticastMain.java

License:Mozilla Public License

public static void main(String[] args) {
    Options options = getOptions();/* w w  w.  j a v a2 s  .c o m*/
    CommandLineParser parser = new GnuParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption('?')) {
            usage(options);
            System.exit(0);
        }

        String hostName = strArg(cmd, 'h', "localhost");
        int portNumber = intArg(cmd, 'p', AMQP.PROTOCOL.PORT);
        String exchangeType = strArg(cmd, 't', "direct");
        String exchangeName = strArg(cmd, 'e', exchangeType);
        int samplingInterval = intArg(cmd, 'i', 1);
        int rateLimit = intArg(cmd, 'r', 0);
        int producerCount = intArg(cmd, 'x', 1);
        int messageCount = intArg(cmd, 'N', 0);
        int consumerCount = intArg(cmd, 'y', 1);
        int connectionCount = cmd.hasOption('c') ? 1 : consumerCount;
        int producerTxSize = intArg(cmd, 'm', 0);
        int consumerTxSize = intArg(cmd, 'n', 0);
        boolean autoAck = cmd.hasOption('a');
        int prefetchCount = intArg(cmd, 'q', 0);
        int minMsgSize = intArg(cmd, 's', 0);
        int timeLimit = intArg(cmd, 'z', 0);
        List<String> flags = lstArg(cmd, 'f');
        int frameMax = intArg(cmd, 'M', 0);
        int heartbeat = intArg(cmd, 'b', 0);

        // setup
        String id = UUID.randomUUID().toString();
        Stats stats = new Stats(1000L * samplingInterval);
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(hostName);
        factory.setPort(portNumber);
        factory.setRequestedFrameMax(frameMax);
        factory.setRequestedHeartbeat(heartbeat);

        Connection[] consumerConnections = new Connection[connectionCount];
        for (int i = 0; i < connectionCount; i++) {
            Connection conn = factory.newConnection();
            consumerConnections[i] = conn;
        }
        Thread[] consumerThreads = new Thread[consumerCount];
        for (int i = 0; i < consumerCount; i++) {
            System.out.println("starting consumer #" + i);
            Connection conn = consumerConnections[i % connectionCount];
            Channel channel = conn.createChannel();
            if (consumerTxSize > 0)
                channel.txSelect();
            channel.exchangeDeclare(exchangeName, exchangeType);
            String queueName = channel.queueDeclare("", flags.contains("persistent"), true, false, null)
                    .getQueue();
            QueueingConsumer consumer = new QueueingConsumer(channel);
            if (prefetchCount > 0)
                channel.basicQos(prefetchCount);
            channel.basicConsume(queueName, autoAck, consumer);
            channel.queueBind(queueName, exchangeName, id);
            Thread t = new Thread(new Consumer(consumer, id, consumerTxSize, autoAck, stats, timeLimit));
            consumerThreads[i] = t;
            t.start();
        }
        Thread[] producerThreads = new Thread[producerCount];
        Connection[] producerConnections = new Connection[producerCount];
        for (int i = 0; i < producerCount; i++) {
            System.out.println("starting producer #" + i);
            Connection conn = factory.newConnection();
            producerConnections[i] = conn;
            Channel channel = conn.createChannel();
            if (producerTxSize > 0)
                channel.txSelect();
            channel.exchangeDeclare(exchangeName, exchangeType);
            final Producer p = new Producer(channel, exchangeName, id, flags, producerTxSize,
                    1000L * samplingInterval, rateLimit, minMsgSize, timeLimit, messageCount);
            channel.addReturnListener(p);
            Thread t = new Thread(p);
            producerThreads[i] = t;
            t.start();
        }

        for (int i = 0; i < producerCount; i++) {
            producerThreads[i].join();
            producerConnections[i].close();
        }

        for (int i = 0; i < consumerCount; i++) {
            consumerThreads[i].join();
        }
        for (int i = 0; i < connectionCount; i++) {
            consumerConnections[i].close();
        }

    } catch (ParseException exp) {
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
        usage(options);
    } catch (Exception e) {
        System.err.println("Main thread caught exception: " + e);
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:ws.ament.hammock.rabbitmq.ConnectionFactoryProducer.java

License:Apache License

@Produces
@ApplicationScoped/*from   w  w w . j a va  2 s.co  m*/
public ConnectionFactory createConnectionFactory(RabbitMQConfiguration rabbitMQConfiguration) {
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setAutomaticRecoveryEnabled(rabbitMQConfiguration.isAutomaticRecovery());
    connectionFactory.setClientProperties(rabbitMQConfiguration.getClientProperties());
    connectionFactory.setConnectionTimeout(rabbitMQConfiguration.getConnectionTimeout());
    connectionFactory.setExceptionHandler(rabbitMQConfiguration.getExceptionHandler());
    connectionFactory.setHandshakeTimeout(rabbitMQConfiguration.getHandshakeTimeout());
    connectionFactory.setHeartbeatExecutor(rabbitMQConfiguration.getHeartbeatExecutor());
    connectionFactory.setMetricsCollector(rabbitMQConfiguration.getMetricsCollector());
    connectionFactory.setHost(rabbitMQConfiguration.getHost());
    connectionFactory.setNetworkRecoveryInterval(rabbitMQConfiguration.getNetworkRecoveryInterval());
    if (rabbitMQConfiguration.isNio()) {
        connectionFactory.useNio();
        connectionFactory.setNioParams(rabbitMQConfiguration.getNioParams());
    }
    connectionFactory.setPassword(rabbitMQConfiguration.getPassword());
    connectionFactory.setPort(rabbitMQConfiguration.getPort());
    connectionFactory.setRequestedChannelMax(rabbitMQConfiguration.getRequestedChannelMax());
    connectionFactory.setRequestedFrameMax(rabbitMQConfiguration.getRequestedFrameMax());
    connectionFactory.setRequestedHeartbeat(rabbitMQConfiguration.getRequestedHeartbeat());
    connectionFactory.setSaslConfig(rabbitMQConfiguration.getSaslConfig());
    connectionFactory.setSharedExecutor(rabbitMQConfiguration.getSharedExecutor());
    connectionFactory.setShutdownExecutor(rabbitMQConfiguration.getShutdownExecutor());
    connectionFactory.setShutdownTimeout(rabbitMQConfiguration.getShutdownTimeout());
    connectionFactory.setSocketConfigurator(rabbitMQConfiguration.getSocketConf());
    connectionFactory.setSocketFactory(rabbitMQConfiguration.getFactory());
    connectionFactory.setThreadFactory(rabbitMQConfiguration.getThreadFactory());
    connectionFactory.setTopologyRecoveryEnabled(rabbitMQConfiguration.isTopologyRecovery());
    try {
        connectionFactory.setUri(rabbitMQConfiguration.getUri());
    } catch (Exception e) {
        throw new RuntimeException("Unable to populate URI ", e);
    }
    connectionFactory.setUsername(rabbitMQConfiguration.getUsername());
    connectionFactory.setVirtualHost(rabbitMQConfiguration.getVirtualHost());
    if (rabbitMQConfiguration.getSslContext() != null) {
        connectionFactory.useSslProtocol(rabbitMQConfiguration.getSslContext());
    }
    return connectionFactory;
}