• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ConnectionOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.jodah.lyra.ConnectionOptions的典型用法代码示例。如果您正苦于以下问题:Java ConnectionOptions类的具体用法?Java ConnectionOptions怎么用?Java ConnectionOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConnectionOptions类属于net.jodah.lyra包,在下文中一共展示了ConnectionOptions类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createConnection

import net.jodah.lyra.ConnectionOptions; //导入依赖的package包/类
public static Connection createConnection(final ProcessContext context) throws IOException, TimeoutException {

        Config config = new Config();
        final String rabbitHost = context.getProperty(RABBITMQ_HOST).getValue();
        final int rabbitPort = context.getProperty(RABBITMQ_PORT).asInteger();
        final String rabbitVirtualHost = context.getProperty(RABBITMQ_VIRTUALHOST).getValue();
        final String rabbitUsername = context.getProperty(RABBITMQ_USERNAME).getValue();
        final String rabbitPassword = context.getProperty(RABBITMQ_PASSWORD).getValue();


        config = config.withRecoveryPolicy(RecoveryPolicies.recoverAlways())
                .withRetryPolicy(new RetryPolicy()
                        .withMaxAttempts(200)
                        .withInterval(Duration.seconds(1))
                        .withMaxDuration(Duration.minutes(5)));

        ConnectionOptions options = new ConnectionOptions()
                .withHost(rabbitHost)
                .withPort(rabbitPort)
                .withVirtualHost(rabbitVirtualHost)
                .withUsername(rabbitUsername)
                .withPassword(rabbitPassword);

        return Connections.create(options, config);
    }
 
开发者ID:MDL,项目名称:nifi-rabbitmq-bundle,代码行数:26,代码来源:RabbitMQFactory.java


示例2: createAmqpConnection

import net.jodah.lyra.ConnectionOptions; //导入依赖的package包/类
public static Connection createAmqpConnection(final ExecutorService executor, Config config) throws IOException
{
    final ConnectionOptions options = new ConnectionOptions()
            .withConsumerExecutor(executor)
            .withPort(config.getInt("amqp.port"))
            .withHost(config.getString("amqp.host"))
            .withUsername(config.getString("amqp.user"))
            .withPassword(config.getString("amqp.pass"))
            .withVirtualHost(config.getString("amqp.vhost"));

    final net.jodah.lyra.config.Config c = new net.jodah.lyra.config.Config()
        .withRecoveryPolicy(RecoveryPolicies.recoverAlways())
        .withRetryPolicy(new RetryPolicy().withBackoff(Duration.seconds(1), Duration.seconds(30)));

    return Connections.create(options, c);
}
 
开发者ID:instaclick,项目名称:amqp-to-hdfs-shovel,代码行数:17,代码来源:ShovelConfig.java


示例3: createRabbitmqConnection

import net.jodah.lyra.ConnectionOptions; //导入依赖的package包/类
public static Connection createRabbitmqConnection(String host, int port, String user, String password) throws IOException, TimeoutException {
    Config config = new Config()
            .withRecoveryPolicy(new RecoveryPolicy()
                    .withBackoff(Duration.seconds(1), Duration.seconds(30))
                    .withMaxAttempts(20));
    ConnectionOptions options = new ConnectionOptions()
            .withHost(host)
            .withPort(port)
            .withUsername(user)
            .withPassword(password);

    return Connections.create(options, config);
}
 
开发者ID:simpleci,项目名称:simpleci,代码行数:14,代码来源:ConnectionUtils.java


示例4: start

import net.jodah.lyra.ConnectionOptions; //导入依赖的package包/类
@PostConstruct
public void start() throws IOException, TimeoutException {
    // millis
    connectionFactory.setConnectionTimeout(1000);
    // seconds
    connectionFactory.setRequestedHeartbeat(4);
    // lyra reconnect logic
    Config config = new Config()
            .withRecoveryPolicy(new RecoveryPolicy()
                    .withMaxAttempts(-1)
                    .withInterval(Duration.seconds(1)))
            .withChannelListeners(this);

    ConnectionOptions connectionOptions = new ConnectionOptions(connectionFactory)
            .withHosts(StringUtils.commaDelimitedListToStringArray(rabbitmqHosts))
            .withPort(rabbitmqPort)
            .withUsername(username)
            .withPassword(password);
    // create single connection
    //clientConnection = connectionFactory.newConnection(Address.parseAddresses(rabbitmqHosts));
    clientConnection = Connections.create(connectionOptions,config);
    // create a seperate producer and a seperate consumer channel
    consumerChannel = clientConnection.createChannel();
    consumerChannel.basicQos(prefetchCount);
    producerChannel = clientConnection.createChannel();
    // ensure the exchange is there
    consumerChannel.exchangeDeclare(exchangeName,"direct",true);
    if(ackType == BUFFERED) {
        messageAcker = new BufferingMessageAcker(consumerChannel);
    } else if(ackType == WRITE_BEHIND) {
        messageAcker = new WriteBehindMessageAcker(consumerChannel);
    } else if(ackType == ASYNC) {
        messageAcker = new AsyncMessageAcker(consumerChannel);
    } else {
        messageAcker = new DirectMessageAcker(consumerChannel);
    }
    messageAcker.start();
}
 
开发者ID:elasticsoftwarefoundation,项目名称:elasticactors,代码行数:39,代码来源:RabbitMQMessagingService.java


示例5: ConnectionHandler

import net.jodah.lyra.ConnectionOptions; //导入依赖的package包/类
public ConnectionHandler(ConnectionOptions options, Config config, ClassLoader classLoader) throws IOException {
  this.options = options;
  this.config = config;
  this.classLoader = Assert.notNull(classLoader, "classLoader");
  this.connectionName =
      options.getName() == null ? String.format("cxn-%s", CONNECTION_COUNTER.incrementAndGet())
          : options.getName();
  consumerThreadPool =
      options.getConsumerExecutor() == null ? Executors.newCachedThreadPool(new NamedThreadFactory(
          String.format("rabbitmq-%s-consumer", connectionName), config.isUsingDaemonThreads())) : options.getConsumerExecutor();
}
 
开发者ID:jhalterman,项目名称:lyra,代码行数:12,代码来源:ConnectionHandler.java


示例6: mockConnection

import net.jodah.lyra.ConnectionOptions; //导入依赖的package包/类
protected void mockConnection() throws IOException, TimeoutException {
  if (connectionFactory == null) {
    mockConnectionOnly();
    connectionFactory = mock(ConnectionFactory.class);
    when(connectionFactory.getVirtualHost()).thenReturn("/");
    when(connectionFactory.newConnection(any(ExecutorService.class), any(Address[].class), anyString()))
        .thenReturn(connection);
  }

  if (options == null)
    options = new ConnectionOptions().withHost("test-host");
  options.withConnectionFactory(connectionFactory);
  if (config == null)
    config =
        new Config().withRetryPolicy(
            RetryPolicies.retryAlways().withInterval(Duration.millis(10))).withRecoveryPolicy(
            RecoveryPolicies.recoverAlways());

  if (connectionHandler == null) {
    connectionHandler = new ConnectionHandler(options, config, Connection.class.getClassLoader());
    connectionProxy =
        (ConfigurableConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
            new Class<?>[] {ConfigurableConnection.class}, connectionHandler);
    connectionHandler.createConnection(connectionProxy);
    channels = new HashMap<Integer, MockChannel>();
  }
}
 
开发者ID:jhalterman,项目名称:lyra,代码行数:28,代码来源:AbstractFunctionalTest.java


示例7: start

import net.jodah.lyra.ConnectionOptions; //导入依赖的package包/类
@PostConstruct
public void start() throws IOException, TimeoutException {
    // millis
    connectionFactory.setConnectionTimeout(1000);
    // seconds
    connectionFactory.setRequestedHeartbeat(4);
    // lyra reconnect logic
    Config config = new Config()
            .withRecoveryPolicy(new RecoveryPolicy()
                    .withMaxAttempts(-1)
                    .withInterval(Duration.seconds(1)))
            .withChannelListeners(this);

    ConnectionOptions connectionOptions = new ConnectionOptions(connectionFactory)
            .withHosts(StringUtils.commaDelimitedListToStringArray(rabbitmqHosts))
            .withPort(rabbitmqPort)
            .withUsername(username)
            .withPassword(password);
    // create single connection
    //clientConnection = connectionFactory.newConnection(Address.parseAddresses(rabbitmqHosts));
    clientConnection = Connections.create(connectionOptions,config);
    // create a seperate consumer channel
    consumerChannel = clientConnection.createChannel();
    consumerChannel.basicQos(prefetchCount);
    // prepare the consumer channels
    for (int i = 0; i < queueExecutor.getThreadCount(); i++) {
        producerChannels.add(clientConnection.createChannel());
    }
    // ensure the exchange is there
    consumerChannel.exchangeDeclare(exchangeName,"direct",true);
    if(ackType == BUFFERED) {
        messageAcker = new BufferingMessageAcker(consumerChannel);
    } else if(ackType == WRITE_BEHIND) {
        messageAcker = new WriteBehindMessageAcker(consumerChannel);
    } else if(ackType == ASYNC) {
        messageAcker = new AsyncMessageAcker(consumerChannel);
    } else {
        messageAcker = new DirectMessageAcker(consumerChannel);
    }
    messageAcker.start();
}
 
开发者ID:elasticsoftwarefoundation,项目名称:elasticactors,代码行数:42,代码来源:RabbitMQMessagingService.java



注:本文中的net.jodah.lyra.ConnectionOptions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UntrustedIdentityException类代码示例发布时间:2022-05-22
下一篇:
Java HandlerMapping类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap