Example usage for com.rabbitmq.client ConnectionFactory DEFAULT_HOST

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

Introduction

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

Prototype

String DEFAULT_HOST

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

Click Source Link

Document

The default host

Usage

From source file:amqp.AmqpEventSource.java

License:Apache License

public static SourceFactory.SourceBuilder builder() {
    return new SourceFactory.SourceBuilder() {
        @Override/*w w w. j a 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:com.adr.data.rabbitmq.RabbitServer.java

License:Apache License

public RabbitServer(String dataqueue, String queryqueue, DataLink datalink, QueryLink querylink) {
    this.host = ConnectionFactory.DEFAULT_HOST; // localhost
    this.port = ConnectionFactory.DEFAULT_AMQP_PORT; // 5672
    this.queryqueue = queryqueue;
    this.dataqueue = dataqueue;
    this.datalink = datalink;
    this.querylink = querylink;
}

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.objectweb.joram.mom.dest.amqp.AmqpConnectionService.java

License:Open Source License

/**
 * Adds an AMQP server and starts a live connection with it, accessible via
 * the host and port provided. A server is uniquely identified by the given
 * name. Adding an existing server won't do anything.
 * /*from   w w w .  j a v  a  2 s . c  o  m*/
 * @param urls the amqp url list identifying the servers separate by space.
 * ex: amqp://user:pass@localhost:5672/?name=serv1 amqp://user:pass@localhost:5678/?name=serv2
 * serv1 and serv2 are the name identifying the server.
 */
public static void addServer(String urls) {
    if (logger.isLoggable(BasicLevel.DEBUG)) {
        logger.log(BasicLevel.DEBUG, "AmqpConnectionService.addServer(" + urls + ')');
    }

    StringTokenizer tk = new StringTokenizer(urls);
    while (tk.hasMoreTokens()) {
        URL url = null;
        try {
            url = new URL(null, tk.nextToken(), new MyURLStreamHandler());
        } catch (Exception e) {
            if (logger.isLoggable(BasicLevel.ERROR)) {
                logger.log(BasicLevel.ERROR, "AmqpConnectionService.addServer : Exception ", e);
            }
            continue;
        }
        String host = null;
        int port = -1;
        String name = "default";
        String userName = null;
        String userPass = null;

        String userInfo = url.getUserInfo();
        if (userInfo != null) {
            StringTokenizer token = new StringTokenizer(userInfo, ":");
            if (token.hasMoreTokens())
                userName = token.nextToken();
            if (token.hasMoreTokens())
                userPass = token.nextToken();
        }

        host = url.getHost();
        if (host == null)
            host = ConnectionFactory.DEFAULT_HOST;

        port = url.getPort();
        if (port < 0)
            port = ConnectionFactory.DEFAULT_AMQP_PORT;

        String query = url.getQuery();
        if (query != null) {
            int index = query.indexOf('=');
            if (index > 0)
                name = query.substring(index + 1, query.length());
        }

        if (logger.isLoggable(BasicLevel.DEBUG)) {
            logger.log(BasicLevel.DEBUG, "AmqpConnectionService.addServer(" + name + ", " + host + ", " + port
                    + ", " + userName + ')');
        }
        getInstance().addServer(name, host, port, userName, userPass);
    }
}

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;
}