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


Java ConnectionFactory.setConnectionTimeout方法代碼示例

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


在下文中一共展示了ConnectionFactory.setConnectionTimeout方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: create

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
static ConnectionProvider create(final RabbitMqConfig config, final DefaultSslConfigurator sslConfigurator) {
    final ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setUsername(config.username());
    connectionFactory.setPassword(config.password());
    connectionFactory.setVirtualHost(config.virtualHost());
    connectionFactory.setAutomaticRecoveryEnabled(config.networkRecoveryEnabled());
    connectionFactory.setTopologyRecoveryEnabled(config.topologyRecoveryEnabled());
    connectionFactory.setConnectionTimeout((int) config.connectionTimeout().toMillis());
    connectionFactory.setHandshakeTimeout((int) config.handshakeTimeout().toMillis());
    connectionFactory.setShutdownTimeout((int) config.shutdownTimeout().toMillis());
    connectionFactory.setNetworkRecoveryInterval(config.networkRecoveryInterval().toMillis());
    connectionFactory.setRequestedHeartbeat((int) config.heartbeat().getSeconds());
    connectionFactory.setRequestedChannelMax(config.channelLimit());
    connectionFactory.setRequestedFrameMax(config.frameSizeLimit());
    if (config.nonBlockingIoEnabled()) {
        connectionFactory.useNio();
    } else {
        connectionFactory.useBlockingIo();
    }
    if (config.sslEnabled()) {
        sslConfigurator.configure(connectionFactory, config);
    }
    return new RabbitConnectionProvider(config, connectionFactory);
}
 
開發者ID:FinderSystems,項目名稱:Elmer,代碼行數:25,代碼來源:RabbitConnectionProvider.java

示例3: createConnectionFactory

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
private ConnectionFactory createConnectionFactory() throws IOException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(this.config.getUsername());
    factory.setPassword(this.config.getPassword());
    factory.setVirtualHost(this.config.getVirtualHost());

    factory.setAutomaticRecoveryEnabled(true);
    factory.setConnectionTimeout(this.config.getConnectionTimeout());
    factory.setNetworkRecoveryInterval(this.config.getNetworkRecoveryInterval());

    if (this.threadFactory != null) {
        factory.setThreadFactory(this.threadFactory);
    }

    return factory;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:17,代碼來源:QueueClient.java

示例4: 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

示例5: 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

示例6: build

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
@Override
public ConnectionFactory build(String config) throws Exception {
	final Context context = new ContextImpl(config);
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(getString(context, RABBITMQ_HOST, "localhost"));
	factory.setPort(getInt(context, RABBITMQ_PORT, 5672));
	factory.setUsername(getString(context, RABBITMQ_USERNAME, null));
	factory.setPassword(getString(context, RABBITMQ_PASSWORD, null));
	factory.setConnectionTimeout(context.getInt(RABBITMQ_CONNECT_TIMEOUT, 30000));
	factory.setAutomaticRecoveryEnabled(context.getBoolean(RABBITMQ_AUTOMATIC_RECOVERY, true));
	return factory;
}
 
開發者ID:shirdrn,項目名稱:scheduled,代碼行數:13,代碼來源:ResourceUtils.java

示例7: build

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
@Override
public ConnectionFactory build(String config) {
	final Context context = new ContextImpl(config);
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(getString(context, RABBITMQ_HOST, "localhost"));
	factory.setPort(getInt(context, RABBITMQ_PORT, 5672));
	factory.setUsername(getString(context, RABBITMQ_USERNAME, null));
	factory.setPassword(getString(context, RABBITMQ_PASSWORD, null));
	factory.setConnectionTimeout(context.getInt(RABBITMQ_CONNECT_TIMEOUT, 30000));
	factory.setAutomaticRecoveryEnabled(context.getBoolean(RABBITMQ_AUTOMATIC_RECOVERY, true));
	return factory;
}
 
開發者ID:shirdrn,項目名稱:runp,代碼行數:13,代碼來源:ResourceUtils.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: createFactoryFor

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
public ConnectionFactory createFactoryFor(final RabbitMQEndpoint endpoint) {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(endpoint.getUsername());
    factory.setPassword(endpoint.getPassword());
    factory.setVirtualHost(endpoint.getVhost());
    factory.setHost(endpoint.getHostname());
    factory.setPort(endpoint.getPortNumber());
    if (endpoint.getClientProperties() != null) {
        factory.setClientProperties(endpoint.getClientProperties());
    }
    factory.setConnectionTimeout(endpoint.getConnectionTimeout());
    factory.setRequestedChannelMax(endpoint.getRequestedChannelMax());
    factory.setRequestedFrameMax(endpoint.getRequestedFrameMax());
    factory.setRequestedHeartbeat(endpoint.getRequestedHeartbeat());
    if (endpoint.getSslProtocol() != null) {
        try {
            if (endpoint.getSslProtocol().equals("true")) {
                factory.useSslProtocol();
            } else if (endpoint.getTrustManager() == null) {
                factory.useSslProtocol(endpoint.getSslProtocol());
            } else {
                factory.useSslProtocol(endpoint.getSslProtocol(), endpoint.getTrustManager());
            }
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            throw new IllegalArgumentException("Invalid sslProtocol " + endpoint.getSslProtocol(), e);
        }
    }
    if (endpoint.getAutomaticRecoveryEnabled() != null) {
        factory.setAutomaticRecoveryEnabled(endpoint.getAutomaticRecoveryEnabled());
    }
    if (endpoint.getNetworkRecoveryInterval() != null) {
        factory.setNetworkRecoveryInterval(endpoint.getNetworkRecoveryInterval());
    }
    if (endpoint.getTopologyRecoveryEnabled() != null) {
        factory.setTopologyRecoveryEnabled(endpoint.getTopologyRecoveryEnabled());
    }
    return factory;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:39,代碼來源:RabbitMQConnectionFactorySupport.java

示例10: createConnection

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
private synchronized Connection createConnection(ChannelType connectionType) throws ConnectionFailureException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date startTime = new Date();
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    settings.getClient_properties().put("connection_type", connectionType.toString());
    settings.getClient_properties().put("connect_time", sdf.format(startTime)+"Z");

    ConnectionFactory cf = new ConnectionFactory();
    cf.setRequestedHeartbeat(settings.getHeartbeat());
    cf.setConnectionTimeout(settings.getConnection_timeout_millis());
    cf.setShutdownTimeout(settings.getShutdown_timeout_millis());
    cf.setRequestedFrameMax(settings.getFrame_max());
    cf.setHandshakeTimeout(settings.getHandshake_timeout_millis());
    cf.setClientProperties((Map)settings.getClient_properties());
    //cf.setSocketConfigurator(); NOTE is this worth investigating??
    cf.setRequestedChannelMax(0);//Hard coded ..
    cf.setAutomaticRecoveryEnabled(false);//Hard coded ..
    cf.setTopologyRecoveryEnabled(false);//Hard coded ..

    Exception lastException = null;
    Connection connection = null;
    for (BrokerAddresses.BrokerAddress address : addresses) {
        cf.setPassword(address.password);
        cf.setUsername(address.username);
        cf.setPort(address.port);
        cf.setHost(address.host);
        cf.setVirtualHost(address.virtualHost);
        try {
            if(address.scheme.toLowerCase().equals("amqps")){
                cf.useSslProtocol();
                cf.setSocketFactory(SSLSocketFactory.getDefault()); //Because rabbit uses NoopTrustStore by default...
            }
            log.infoWithParams("Creating "+connectionType+" connection to broker ...",
                    "address", address.toString(),
                    "settings", settings.toString());
            connection = cf.newConnection();
            boolean isOpen = connection.isOpen();
            if(!isOpen){
                continue;
            }
            break;
        } catch (Exception e) {
            log.debugWithParams("Failed to createConnection to broker",
                    "address", address.toString());
            lastException = e;
        }
    }

    if(connection == null){
        throw new ConnectionFailureException(cf, lastException);
    }

    conToChannel.put(connectionType,
            new ConnectionInfo(
                    connection,
                    new ArrayList<ChannelImpl>(),
                    settings.getClient_properties(),
                    connectionType)
    );
    log.infoWithParams("Successfully created "+connectionType+" connection to broker.",
            "address", addresses.get(0).toString(),
            "localPort", ((AMQConnection) connection).getLocalPort(),
            "settings", settings.toString());

    return connection;

}
 
開發者ID:meltwater,項目名稱:rxrabbit,代碼行數:68,代碼來源:DefaultChannelFactory.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

示例12: RmqChannel

import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
/**
 * initialize rabbit mq listener
 * 
 * @param builder properties to init channel.
 * @throws Exception if failed.
 */
public RmqChannel(Rmq.Builder builder) throws Exception {

  final ConnectionFactory factory = new ConnectionFactory();

  factory.setHost(builder.host());

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

  factory.setConnectionTimeout(builder.timeout());

  factory.setAutomaticRecoveryEnabled(builder.autoRecovery());
  factory.setNetworkRecoveryInterval(builder.networkRecoveryInterval());

  if (builder.credentials() != null && builder.credentials() instanceof BasicCredentials) {
    BasicCredentials basic = (BasicCredentials) builder.credentials();
    factory.setUsername(basic.username());
    factory.setPassword(basic.password());
  }


  this.connection = factory.newConnection();
  this.channel = connection.createChannel();

}
 
開發者ID:scalecube,項目名稱:RabbitMQ-gateway,代碼行數:33,代碼來源:RmqChannel.java


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