Example usage for com.rabbitmq.client ConnectionFactory DEFAULT_USER

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

Introduction

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

Prototype

String DEFAULT_USER

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

Click Source Link

Document

Default user name

Usage

From source file:amqp.AmqpEventSource.java

License:Apache License

public static SourceFactory.SourceBuilder builder() {
    return new SourceFactory.SourceBuilder() {
        @Override//from w  w w  .  ja  v  a  2s.c  o 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:io.druid.examples.rabbitmq.RabbitMQFirehoseFactoryTest.java

License:Apache License

@Test
public void testDefaultSerde() throws Exception {
    RabbitMQFirehoseConfig config = RabbitMQFirehoseConfig.makeDefaultConfig();

    JacksonifiedConnectionFactory connectionFactory = JacksonifiedConnectionFactory
            .makeDefaultConnectionFactory();

    RabbitMQFirehoseFactory factory = new RabbitMQFirehoseFactory(connectionFactory, config);

    byte[] bytes = mapper.writeValueAsBytes(factory);
    RabbitMQFirehoseFactory factory2 = mapper.readValue(bytes, RabbitMQFirehoseFactory.class);
    byte[] bytes2 = mapper.writeValueAsBytes(factory2);

    Assert.assertArrayEquals(bytes, bytes2);

    Assert.assertEquals(factory.getConfig(), factory2.getConfig());
    Assert.assertEquals(factory.getConnectionFactory(), factory2.getConnectionFactory());

    Assert.assertEquals(300, factory2.getConfig().getMaxDurationSeconds());

    Assert.assertEquals(ConnectionFactory.DEFAULT_HOST, factory2.getConnectionFactory().getHost());
    Assert.assertEquals(ConnectionFactory.DEFAULT_USER, factory2.getConnectionFactory().getUsername());
    Assert.assertEquals(ConnectionFactory.DEFAULT_AMQP_PORT, factory2.getConnectionFactory().getPort());
}

From source file:org.apache.druid.examples.rabbitmq.RabbitMQFirehoseFactoryTest.java

License:Apache License

@Test
public void testDefaultSerde() throws Exception {
    RabbitMQFirehoseConfig config = RabbitMQFirehoseConfig.makeDefaultConfig();

    JacksonifiedConnectionFactory connectionFactory = JacksonifiedConnectionFactory
            .makeDefaultConnectionFactory();

    RabbitMQFirehoseFactory factory = new RabbitMQFirehoseFactory(connectionFactory, config, null);

    byte[] bytes = mapper.writeValueAsBytes(factory);
    RabbitMQFirehoseFactory factory2 = mapper.readValue(bytes, RabbitMQFirehoseFactory.class);
    byte[] bytes2 = mapper.writeValueAsBytes(factory2);

    Assert.assertArrayEquals(bytes, bytes2);

    Assert.assertEquals(factory.getConfig(), factory2.getConfig());
    Assert.assertEquals(factory.getConnectionFactory(), factory2.getConnectionFactory());

    Assert.assertEquals(300, factory2.getConfig().getMaxDurationSeconds());

    Assert.assertEquals(ConnectionFactory.DEFAULT_HOST, factory2.getConnectionFactory().getHost());
    Assert.assertEquals(ConnectionFactory.DEFAULT_USER, factory2.getConnectionFactory().getUsername());
    Assert.assertEquals(ConnectionFactory.DEFAULT_AMQP_PORT, factory2.getConnectionFactory().getPort());
}

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.apache.flume.RabbitMQUtil.java

License:Apache License

public static ConnectionFactory getFactory(Context context) {
    Preconditions.checkArgument(context != null, "context cannot be null.");
    ConnectionFactory factory = new ConnectionFactory();

    String hostname = context.getString("hostname");
    Preconditions.checkArgument(hostname != null, "No hostname specified.");
    factory.setHost(hostname);/*from w  w w. j  ava 2s  .c om*/

    int port = context.getInteger(RabbitMQConstants.CONFIG_PORT, -1);

    if (-1 != port) {
        factory.setPort(port);
    }

    String username = context.getString(RabbitMQConstants.CONFIG_USERNAME);

    if (null == username) {
        factory.setUsername(ConnectionFactory.DEFAULT_USER);
    } else {
        factory.setUsername(username);
    }

    String password = context.getString(RabbitMQConstants.CONFIG_PASSWORD);

    if (null == password) {
        factory.setPassword(ConnectionFactory.DEFAULT_PASS);
    } else {
        factory.setPassword(password);
    }

    String virtualHost = context.getString(RabbitMQConstants.CONFIG_VIRTUALHOST);

    if (null != virtualHost) {
        factory.setVirtualHost(virtualHost);
    }

    int connectionTimeout = context.getInteger(RabbitMQConstants.CONFIG_CONNECTIONTIMEOUT, -1);

    if (connectionTimeout > -1) {
        factory.setConnectionTimeout(connectionTimeout);
    }

    //        boolean useSSL = context.getBoolean("usessl", false);
    //        if(useSSL){
    //            factory.useSslProtocol();
    //        }

    return factory;
}

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");
    }//  w  ww  .  j  a  va2  s  .c  om

    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.
 *//*w  w  w  .java  2s. 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());
}

From source file:ox.softeng.burst.service.message.RabbitMessageService.java

public RabbitMessageService(EntityManagerFactory emf, Properties properties)
        throws IOException, TimeoutException {

    exchange = properties.getProperty("rabbitmq.exchange");
    queue = properties.getProperty("rabbitmq.queue");
    entityManagerFactory = emf;/*from   w  w w  .ja  va2 s  .c  o  m*/
    consumerCount = Utils.convertToInteger("message.service.thread.size",
            properties.getProperty("message.service.consumer.size"), 1);

    String host = properties.getProperty("rabbitmq.host");
    String username = properties.getProperty("rabbitmq.user", ConnectionFactory.DEFAULT_USER);
    String password = properties.getProperty("rabbitmq.password", ConnectionFactory.DEFAULT_PASS);
    Integer port = Utils.convertToInteger("rabbitmq.port", properties.getProperty("rabbitmq.port"),
            ConnectionFactory.DEFAULT_AMQP_PORT);

    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setPort(port);
    factory.setHost(host);
    factory.setAutomaticRecoveryEnabled(true);
    factory.setThreadFactory(new NamedThreadFactory("consumer"));

    connection = factory.newConnection();

    logger.info("Creating new RabbitMQ Service using: \n" + "  host: {}:{}\n" + "  user: {}\n"
            + "  exchange: {}\n" + "  queue: {}", host, port, username, exchange, queue);
}

From source file:ox.softeng.burst.services.BurstService.java

License:Open Source License

public BurstService(Properties properties) {

    logger.info("Starting application version {}", System.getProperty("applicationVersion"));

    // Output env version from potential dockerfile environment
    if (System.getenv("BURST_VERSION") != null)
        logger.info("Docker container build version {}", System.getenv("BURST_VERSION"));

    String user = (String) properties.get("hibernate.connection.user");
    String url = (String) properties.get("hibernate.connection.url");
    String password = (String) properties.get("hibernate.connection.password");

    logger.info("Migrating database using: \n" + "  url: {}" + "  user: {}" + "  password: ****", url, user);
    migrateDatabase(url, user, password);
    entityManagerFactory = Persistence.createEntityManagerFactory("ox.softeng.burst", properties);

    String rabbitMQHost = properties.getProperty("rabbitmq.host");
    String rabbitMQExchange = properties.getProperty("rabbitmq.exchange");
    String rabbitMQQueue = properties.getProperty("rabbitmq.queue");
    String rabbitPortStr = properties.getProperty("rabbitmq.port");
    String rabbitUser = properties.getProperty("rabbitmq.user", ConnectionFactory.DEFAULT_USER);
    String rabbitPassword = properties.getProperty("rabbitmq.password", ConnectionFactory.DEFAULT_PASS);

    Integer rabbitPort = ConnectionFactory.DEFAULT_AMQP_PORT;

    try {//  w w  w  .  j  a  v  a  2s . c  om
        rabbitPort = Integer.parseInt(rabbitPortStr);
    } catch (NumberFormatException ignored) {
        logger.warn("Configuration supplied rabbit port '{}' is not numerical, using default value {}",
                rabbitPortStr, rabbitPort);
    }

    logger.info(
            "Creating new RabbitMQ Service using: \n" + "  host: {}:{}\n" + "  user: {}:{}\n"
                    + "  exchange: {}\n" + "  queue: {}",
            rabbitMQHost, rabbitPort, rabbitUser, rabbitPassword, rabbitMQExchange, rabbitMQQueue);
    try {
        rabbitReceiver = new RabbitService(rabbitMQHost, rabbitPort, rabbitUser, rabbitPassword,
                rabbitMQExchange, rabbitMQQueue, entityManagerFactory);
    } catch (IOException | TimeoutException e) {
        logger.error("Cannot create RabbitMQ service: " + e.getMessage(), e);
        System.exit(1);
    } catch (JAXBException e) {
        logger.error("Cannot create JAXB unmarshaller for messages: " + e.getMessage(), e);
        System.exit(1);
    }

    logger.info("Creating new report scheduler");
    reportScheduler = new ReportScheduler(entityManagerFactory, properties);
    scheduleFrequency = Integer
            .parseInt(properties.getProperty("report.schedule.frequency", SCHEDULE_FREQUENCY.toString()));

    logger.info("Creating new executor with thread pool size {}", THREAD_POOL_SIZE);
    executor = Executors.newScheduledThreadPool(THREAD_POOL_SIZE);
}