Example usage for com.rabbitmq.client ConnectionFactory DEFAULT_VHOST

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

Introduction

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

Prototype

String DEFAULT_VHOST

To view the source code for com.rabbitmq.client ConnectionFactory DEFAULT_VHOST.

Click Source Link

Document

Default virtual host

Usage

From source file:amqp.AmqpEventSource.java

License:Apache License

public static SourceFactory.SourceBuilder builder() {
    return new SourceFactory.SourceBuilder() {
        @Override/*from ww  w . j a v a 2  s  .  co m*/
        public EventSource build(String... args) {
            return build(null, args);
        }

        @Override
        public EventSource build(Context ctx, String... args) {
            if (args.length < 1 || args.length > 13) {
                throw new IllegalArgumentException("amqp(exchangeName=\"exchangeName\" " + "[,host=\"host\"] "
                        + "[,port=port] " + "[,virtualHost=\"virtualHost\"] " + "[,userName=\"user\"] "
                        + "[,password=\"password\"] " + "[,exchangeType=\"direct\"] "
                        + "[,durableExchange=false] " + "[,queueName=\"queueName\"] " + "[,durableQueue=false] "
                        + "[,exclusiveQueue=false] " + "[,autoDeleteQueue=false] "
                        + "[,bindings=\"binding1,binding2,bindingN\"] " + "[,useMessageTimestamp=false])");
            }

            CommandLineParser parser = new CommandLineParser(args);

            String host = parser.getOptionValue("host", ConnectionFactory.DEFAULT_HOST);
            int port = parser.getOptionValue("port", ConnectionFactory.DEFAULT_AMQP_PORT);
            String virtualHost = parser.getOptionValue("virtualHost", ConnectionFactory.DEFAULT_VHOST);
            String userName = parser.getOptionValue("userName", ConnectionFactory.DEFAULT_USER);
            String password = parser.getOptionValue("password", ConnectionFactory.DEFAULT_PASS);
            String exchangeName = parser.getOptionValue("exchangeName");
            String exchangeType = parser.getOptionValue("exchangeType", AmqpConsumer.DEFAULT_EXCHANGE_TYPE);
            boolean durableExchange = parser.getOptionValue("durableExchange", true);
            String queueName = parser.getOptionValue("queueName");
            boolean durableQueue = parser.getOptionValue("durableQueue", false);
            boolean exclusiveQueue = parser.getOptionValue("exclusiveQueue", false);
            boolean autoDeleteQueue = parser.getOptionValue("autoDeleteQueue", false);
            String[] bindings = parser.getOptionValues("bindings");
            boolean useMessageTimestamp = parser.getOptionValue("useMessageTimestamp", false);

            // exchange name is the only required parameter
            if (exchangeName == null) {
                throw new IllegalArgumentException("exchangeName must be set for AMQP source");
            }

            return new AmqpEventSource(host, port, virtualHost, userName, password, exchangeName, exchangeType,
                    durableExchange, queueName, durableQueue, exclusiveQueue, autoDeleteQueue,
                    useMessageTimestamp, bindings);
        }
    };
}

From source file:org.apache.flume.rabbitmq.source.RabbitMQSource.java

License:Apache License

@Override
public void configure(Context context) {
    hosts = context.getString(HOSTNAME, ConnectionFactory.DEFAULT_HOST);

    port = context.getInteger(PORT, ConnectionFactory.DEFAULT_AMQP_PORT);
    virtualHost = context.getString(VIRTUAL_HOST, ConnectionFactory.DEFAULT_VHOST);

    userName = context.getString(USERNAME, ConnectionFactory.DEFAULT_USER);

    password = context.getString(PASSWORD, ConnectionFactory.DEFAULT_PASS);

    connectionTimeout = context.getInteger(CONNECTION_TIMEOUT, ConnectionFactory.DEFAULT_CONNECTION_TIMEOUT);
    requestedHeartbeat = context.getInteger(REQUESTED_HEARTBEAT, ConnectionFactory.DEFAULT_HEARTBEAT);
    requestedChannelMax = context.getInteger(REQUESTED_CHANNEL_MAX, ConnectionFactory.DEFAULT_CHANNEL_MAX);
    requestedFrameMax = context.getInteger(REQUESTED_FRAMEL_MAX, ConnectionFactory.DEFAULT_FRAME_MAX);

    connectionFactory = new RabbitMQConnectionFactory.Builder().addHosts(hosts).setPort(port)
            .setVirtualHost(virtualHost).setUserName(userName).setPassword(password)
            .setConnectionTimeOut(connectionTimeout).setRequestedHeartbeat(requestedHeartbeat)
            .setRequestedChannelMax(requestedChannelMax).setRequestedFrameMax(requestedFrameMax).build();

    exchangeName = context.getString(EXCHANGE_NAME, StringUtils.EMPTY);
    queueName = context.getString(QUEUE_NAME, StringUtils.EMPTY);
    Preconditions.checkArgument(StringUtils.isNotEmpty(exchangeName) || StringUtils.isNotEmpty(queueName),
            "Atleast exchange name or queue name must be defined.");

    topics = StringUtils.split(context.getString(TOPICS, StringUtils.EMPTY), ",");

    String queueParams = context.getString(QUEUE_PARAMETERS, StringUtils.EMPTY);
    queueParameters = initializeQueueParameters(queueParams);

    batchSize = context.getInteger(BATCH_SIZE, DEFAULT_BATCH_SIZE);
}

From source file:org.thingsboard.rule.engine.rabbitmq.TbRabbitMqNodeConfiguration.java

License:Apache License

@Override
public TbRabbitMqNodeConfiguration defaultConfiguration() {
    TbRabbitMqNodeConfiguration configuration = new TbRabbitMqNodeConfiguration();
    configuration.setExchangeNamePattern("");
    configuration.setRoutingKeyPattern("");
    configuration.setMessageProperties(null);
    configuration.setHost(ConnectionFactory.DEFAULT_HOST);
    configuration.setPort(ConnectionFactory.DEFAULT_AMQP_PORT);
    configuration.setVirtualHost(ConnectionFactory.DEFAULT_VHOST);
    configuration.setUsername(ConnectionFactory.DEFAULT_USER);
    configuration.setPassword(ConnectionFactory.DEFAULT_PASS);
    configuration.setAutomaticRecoveryEnabled(false);
    configuration.setConnectionTimeout(ConnectionFactory.DEFAULT_CONNECTION_TIMEOUT);
    configuration.setHandshakeTimeout(ConnectionFactory.DEFAULT_HANDSHAKE_TIMEOUT);
    configuration.setClientProperties(Collections.emptyMap());
    return configuration;
}

From source file:org.voltdb.exportclient.RabbitMQExportClient.java

License:Open Source License

@Override
public void configure(Properties config) throws Exception {
    final String brokerHost = config.getProperty("broker.host");
    final String amqpUri = config.getProperty("amqp.uri");
    if (brokerHost == null && amqpUri == null) {
        throw new IllegalArgumentException("One of \"broker.host\" and \"amqp.uri\" must not be null");
    }/*ww  w  .j  a  va 2  s. co m*/

    final int brokerPort = Integer
            .parseInt(config.getProperty("broker.port", String.valueOf(ConnectionFactory.DEFAULT_AMQP_PORT)));
    final String username = config.getProperty("username", ConnectionFactory.DEFAULT_USER);
    final String password = config.getProperty("password", ConnectionFactory.DEFAULT_PASS);
    final String vhost = config.getProperty("virtual.host", ConnectionFactory.DEFAULT_VHOST);
    m_exchangeName = config.getProperty("exchange.name", "");

    final String routingKeySuffix = config.getProperty("routing.key.suffix");
    if (routingKeySuffix != null) {
        StringTokenizer tokens = new StringTokenizer(routingKeySuffix, ",");
        while (tokens.hasMoreTokens()) {
            String[] parts = tokens.nextToken().split("\\.");
            if (parts.length == 2) {
                m_routingKeyColumns.put(parts[0].toLowerCase().trim(), parts[1].trim());
            }
        }
    }

    m_skipInternal = Boolean.parseBoolean(config.getProperty("skipinternals", "false"));

    if (Boolean.parseBoolean(config.getProperty("queue.durable", "true"))) {
        m_channelProperties = MessageProperties.PERSISTENT_TEXT_PLAIN;
    }

    m_connFactory = new ConnectionFactory();
    // Set the URI first, if other things are set, they'll overwrite the corresponding
    // parts in the URI.
    if (amqpUri != null) {
        m_connFactory.setUri(amqpUri);
    }
    m_connFactory.setHost(brokerHost);
    m_connFactory.setPort(brokerPort);
    m_connFactory.setUsername(username);
    m_connFactory.setPassword(password);
    m_connFactory.setVirtualHost(vhost);

    final TimeZone tz = TimeZone.getTimeZone(config.getProperty("timezone", VoltDB.GMT_TIMEZONE.getID()));

    m_binaryEncoding = ExportDecoderBase.BinaryEncoding
            .valueOf(config.getProperty("binaryencoding", "HEX").trim().toUpperCase());

    m_ODBCDateformat = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            SimpleDateFormat sdf = new SimpleDateFormat(Constants.ODBC_DATE_FORMAT_STRING);
            sdf.setTimeZone(tz);
            return sdf;
        }
    };

    slogger.info("Configured RabbitMQ export client");
}

From source file:org.voltdb.exportclient.TestRabbitMQExportClient.java

License:Open Source License

/**
 * Make sure we use sane defaults for optional config options.
 *//*from   w  ww.  j a  va2  s.c om*/
@Test
public void testDefaultConfig() throws Exception {
    final RabbitMQExportClient dut = new RabbitMQExportClient();
    final Properties config = new Properties();
    config.setProperty("broker.host", "fakehost");
    dut.configure(config);
    assertEquals("fakehost", dut.m_connFactory.getHost());
    assertEquals(ConnectionFactory.DEFAULT_AMQP_PORT, dut.m_connFactory.getPort());
    assertEquals(ConnectionFactory.DEFAULT_USER, dut.m_connFactory.getUsername());
    assertEquals(ConnectionFactory.DEFAULT_PASS, dut.m_connFactory.getPassword());
    assertEquals(ConnectionFactory.DEFAULT_VHOST, dut.m_connFactory.getVirtualHost());
    assertEquals("", dut.m_exchangeName);
    assertTrue(dut.m_routingKeyColumns.isEmpty());
    assertFalse(dut.m_skipInternal);
    assertEquals(MessageProperties.PERSISTENT_TEXT_PLAIN, dut.m_channelProperties);
    assertEquals(ExportDecoderBase.BinaryEncoding.HEX, dut.m_binaryEncoding);
    assertEquals(TimeZone.getTimeZone(VoltDB.GMT_TIMEZONE.getID()), dut.m_ODBCDateformat.get().getTimeZone());
}