當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnectionFactory.setUri方法代碼示例

本文整理匯總了Java中com.rabbitmq.client.ConnectionFactory.setUri方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionFactory.setUri方法的具體用法?Java ConnectionFactory.setUri怎麽用?Java ConnectionFactory.setUri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.rabbitmq.client.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.setUri方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, InterruptedException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri("amqp://guest:[email protected]");
    factory.setConnectionTimeout(300000);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare("my-queue", true, false, false, null);

    int count = 0;

    while (count < 5000) {
        String message = "Message number " + count;

        channel.basicPublish("", "my-queue", null, message.getBytes());
        count++;
        System.out.println("Published message: " + message);

        Thread.sleep(5000);
    }
}
 
開發者ID:nyholmniklas,項目名稱:rabbitmq-tutorial,代碼行數:22,代碼來源:Publisher.java

示例2: main

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
		ConnectionFactory factory = new ConnectionFactory();
//		factory.setHost("");
		factory.setUri("amqp://alpha.netkiller.cn");
		factory.setUsername("admin");
//		factory.setPassword("admin123");
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();

		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		String message = "Hello World!";
		channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
		System.out.println(" [x] Sent '" + message + "'");

		channel.close();
		connection.close();
	}
 
開發者ID:netkiller,項目名稱:ipo,代碼行數:18,代碼來源:RabbitMQTest.java

示例3: open

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
@Override
public void open() {
	try {
		ConnectionFactory factory = new ConnectionFactory();
		// factory.setHost( );

		factory.setUri(this.uri);

		if (this.username != null) {
			factory.setUsername(this.username);
			factory.setPassword(this.password);
		}
		this.connection = factory.newConnection();
		this.channel = this.connection.createChannel();
		channel.queueDeclare(this.queue, false, false, false, null);
	} catch (Exception e) {
		logger.warn(e.getMessage());
	}
}
 
開發者ID:netkiller,項目名稱:ipo,代碼行數:20,代碼來源:RabbitMQOutput.java

示例4: getConnection

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
 * Requests that we load the data for the environment variable configuration set.
 * @return the {@code Connection} configuration for the currently set information
 * @throws RuntimeException if anything goes wrong during data loading
 */
public Connection getConnection() {
  LOG.info("Executing lookup of RabbitMQ configuration from environment");

  String uri = System.getenv("AMQP_URL");
  uri = StringUtils.isBlank(uri) ? System.getenv("RABBITMQ_URL") : uri;
  uri = StringUtils.isBlank(uri) ? System.getProperty("env.AMQP_URL") : uri;
  uri = StringUtils.isBlank(uri) ? System.getProperty("env.RABBITMQ_URL") : uri;
  if (StringUtils.isBlank(uri)) {
    throw new RuntimeException("Unable to find RabbitMQ configuration.");
  }

  // create and return the connection
  try {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri(uri);
    return factory.newConnection();
  } catch (IOException | NoSuchAlgorithmException | URISyntaxException | TimeoutException | KeyManagementException e) {
    throw new RuntimeException(e.getMessage(), e);
  }
}
 
開發者ID:revof11,項目名稱:java-circleci-rabbitmq,代碼行數:26,代碼來源:ConnectionLoader.java

示例5: start

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
 * This is called when a resource adapter instance is bootstrapped.
 *
 * @param ctx
 *            A bootstrap context containing references
 * @throws ResourceAdapterInternalException
 *             indicates bootstrap failure.
 */
public void start(BootstrapContext ctx)
		throws ResourceAdapterInternalException {
	log.tracef("start(%s)", ctx);
	this.bootstrapContext = ctx;
	rabbitCF = new ConnectionFactory();
	try {
		rabbitCF.setUri(uri);
		rabbitCF.setConnectionTimeout(getConnectionTimeout());
		rabbitCF.setRequestedHeartbeat(getRequestedHeartbeat());
	} catch (KeyManagementException | NoSuchAlgorithmException
			| URISyntaxException e) {
		throw new ResourceAdapterInternalException(e);
	}

}
 
開發者ID:leogsilva,項目名稱:rabbitmq-resource-adapter,代碼行數:24,代碼來源:RabbitmqResourceAdapter.java

示例6: main

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, InterruptedException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri("amqp://guest:[email protected]");
    factory.setConnectionTimeout(300000);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare("my-queue", true, false, false, null);

    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume("my-queue", false, consumer);

    while (true) {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();

        if (delivery != null) {
            try {
                String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
                System.out.println("Message consumed: " + message);
                // Interact with IO
                channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
            } catch (Exception e) {
                channel.basicReject(delivery.getEnvelope().getDeliveryTag(), true);
            }
        }
    }

}
 
開發者ID:nyholmniklas,項目名稱:rabbitmq-tutorial,代碼行數:28,代碼來源:Consumer.java

示例7: connect

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
private void connect()
  throws Exception
{
  ConnectionFactory factory = new ConnectionFactory();
  factory.setUri(_config.uri());

  try {
    _conn = factory.newConnection();
    _channel = _conn.createChannel();

    AMQP.Queue.DeclareOk responseQueue = _channel.queueDeclare(_config.queue(), _config.durable(), _config.exclusive(), _config.autoDelete(), null);

    if (! "".equals(_config.exchange())) {
      AMQP.Exchange.DeclareOk responseExchange = _channel.exchangeDeclare(_config.exchange(), _config.exchangeType(), _config.durable(), _config.autoDelete(), false, null);

      _channel.queueBind(responseQueue.getQueue(), _config.exchange(), _config.routingKey());
    }

    _logger.log(Level.INFO, "connect: " + _id + ", actual queue=" + responseQueue.getQueue() + ", " + _config + " . " + _self);
  }
  catch (Exception e) {
    closeChannel();
    closeConnection();

    throw e;
  }
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:28,代碼來源:RabbitPipeImpl.java

示例8: createConnectionFactory

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
 * Creates a Connection Factory instance.
 *
 * @param cxManager
 *          ConnectionManager to be associated with created EIS connection
 *          factory instance
 * @return EIS-specific Connection Factory instance or
 *         javax.resource.cci.ConnectionFactory instance
 * @throws ResourceException
 *           Generic exception
 */
public Object createConnectionFactory(ConnectionManager cxManager)
    throws ResourceException {
  log.tracef("createConnectionFactory(%s)", cxManager);
  rabbitCF = new ConnectionFactory();
  try {
    rabbitCF.setUri(uri);
    rabbitCF.setConnectionTimeout(timeout);
    rabbitCF.setRequestedHeartbeat(requestedHeartbeat);
  } catch (KeyManagementException | NoSuchAlgorithmException
      | URISyntaxException e) {
    throw new ResourceException(e);
  }
  return new RabbitmqConnectionFactoryImpl(this, cxManager);
}
 
開發者ID:leogsilva,項目名稱:rabbitmq-resource-adapter,代碼行數:26,代碼來源:RabbitmqManagedConnectionFactory.java

示例9: withUri

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public BrokerAddressBuilder withUri(URI amqpUri) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
    ConnectionFactory tmp = new ConnectionFactory();
    tmp.setUri(amqpUri);
    cloneConnectionSettings(tmp,amqpUri);
    return this;
}
 
開發者ID:meltwater,項目名稱:rxrabbit,代碼行數:7,代碼來源:BrokerAddresses.java

示例10: withUriString

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public BrokerAddressBuilder withUriString(String amqpUriString) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
    ConnectionFactory tmp = new ConnectionFactory();
    tmp.setUri(amqpUriString);
    cloneConnectionSettings(tmp,new URI(amqpUriString));
    return this;
}
 
開發者ID:meltwater,項目名稱:rxrabbit,代碼行數:7,代碼來源:BrokerAddresses.java

示例11: getConnectionFactory

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
 *
 * @return Connection Factory for RMQ
 * @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;
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:48,代碼來源:RMQConnectionConfig.java


注:本文中的com.rabbitmq.client.ConnectionFactory.setUri方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。