当前位置: 首页>>代码示例>>Java>>正文


Java Address类代码示例

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


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

示例1: testConnectionFactoryWithOverrides

import com.rabbitmq.client.Address; //导入依赖的package包/类
@Test
public void testConnectionFactoryWithOverrides() {
	load(TestConfiguration.class, "spring.rabbitmq.host:remote-server",
			"spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice",
			"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost",
			"spring.rabbitmq.connection-timeout:123");
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
	assertThat(connectionFactory.getPort()).isEqualTo(9000);
	assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
	DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
	com.rabbitmq.client.ConnectionFactory rcf = (com.rabbitmq.client.ConnectionFactory) dfa
			.getPropertyValue("rabbitConnectionFactory");
	assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
	assertThat((Address[]) dfa.getPropertyValue("addresses")).hasSize(1);

}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:RabbitAutoConfigurationTests.java

示例2: initRecv

import com.rabbitmq.client.Address; //导入依赖的package包/类
protected void initRecv()
{
  checkWorkable();
  
  String[] hpArr = getParam().getHostsAndPorts().split(",");
  address = new Address[hpArr.length];
  
  for (int i = 0; i < address.length; i++)
  {
    address[i] = new Address(hpArr[i].split(":")[0], Integer.parseInt(hpArr[i].split(":")[1]));
  }
  
  factory = new ConnectionFactory();
  factory.setUsername(getParam().getUserName());
  factory.setPassword(getParam().getPassward());
  factory.setVirtualHost(getParam().getVhost());
  try
  {
    createConnect();
  }
  catch (IOException e)
  {
    LogUtil.getMqSyncLog().error("Create connect failure.", e);
  }
  LogUtil.getMqSyncLog().info(" Connection and Channel Create Complete. ");
}
 
开发者ID:iisi-nj,项目名称:GemFireLite,代码行数:27,代码来源:RabbitMqReceiver.java

示例3: toString

import com.rabbitmq.client.Address; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public String toString() {
  String adrList = ""; Address[] list = getServerAddressList();
  for ( int i = 0; i < list.length; i++ ) {
    if ( i > 0 ) { adrList += ","; }
    adrList += list[i].getHost()+":"+list[i].getPort();
  }
	return "StandardRabbitExchangeConfiguration" +
		   " (username : " + getUsername() +
		   // REMOVED as it will appear in logs. ", password : " + getPassword() +
		   ", serverAddressList : [" + adrList +
		   "], sslConnection : " + isSSLConnection() +
		   ", exchangeName : " + getExchangeName() +
		   ", exchangeDurable : " + isExchangeDurable() +
		   ", exchangeType : " + getExchangeType() +
		   ")";
}
 
开发者ID:ecosense-au-dk,项目名称:Karibu-core,代码行数:21,代码来源:StandardRabbitExchangeConfiguration.java

示例4: connection

import com.rabbitmq.client.Address; //导入依赖的package包/类
public Connection connection() throws IOException {
    ConnectionFactory factory = new ConnectionFactory();

    factory.setUsername(configuration.username());
    factory.setPassword(configuration.password());
    factory.setVirtualHost(configuration.virtualhost());

    String[] urls = configuration.connectionUrl().split(";");

    List<Address> addresses = new LinkedList<Address>();

    for (String url : urls) {
        String[] urlInf = url.split(":");
        String hostname = urlInf[0];
        int port = parseInt(urlInf[1]);
        addresses.add(new Address(hostname, port));
    }

    return factory.newConnection(addresses.toArray(new Address[addresses.size()]));
}
 
开发者ID:gabfssilva,项目名称:rabbitmq-support,代码行数:21,代码来源:RabbitMQClientFactory.java

示例5: getAddresses

import com.rabbitmq.client.Address; //导入依赖的package包/类
/**
 * Returns the addresses to attempt connections to, in round-robin order.
 * 
 * @see #withAddresses(Address...)
 * @see #withAddresses(String)
 * @see #withHost(String)
 * @see #withHosts(String...)
 */
public Address[] getAddresses() {
  if (addresses != null)
    return addresses;

  if (hosts != null) {
    addresses = new Address[hosts.length];
    for (int i = 0; i < hosts.length; i++)
      addresses[i] = new Address(hosts[i], factory.getPort());
    return addresses;
  }

  Address address = factory == null ? new Address("localhost", -1) : new Address(
      factory.getHost(), factory.getPort());
  return new Address[] { address };
}
 
开发者ID:jhalterman,项目名称:lyra,代码行数:24,代码来源:ConnectionOptions.java

示例6: shouldThrowOnInvocationFailureWithNoRetryPolicy

import com.rabbitmq.client.Address; //导入依赖的package包/类
/**
 * Asserts that invocation failures are rethrown when a retry policy is not set.
 */
public void shouldThrowOnInvocationFailureWithNoRetryPolicy() throws Throwable {
  config = new Config().withRetryPolicy(RetryPolicies.retryNever());
  connectionFactory = mock(ConnectionFactory.class);
  connection = mock(Connection.class);
  when(connectionFactory.newConnection(any(ExecutorService.class), any(Address[].class), anyString())).thenAnswer(
      failNTimes(3, new ConnectException("fail"), connection, connectionHandler));

  try {
    mockConnection();
    fail();
  } catch (Exception expected) {
  }

  verifyCxnCreations(1);
}
 
开发者ID:jhalterman,项目名称:lyra,代码行数:19,代码来源:ConnectionFactoryInvocationTest.java

示例7: connect

import com.rabbitmq.client.Address; //导入依赖的package包/类
@Override
public void connect() throws IOException {
    if(config.getAddresses().isEmpty()) {
        logger.warning("Skipping AMQP connection because no addresses are configured");
    } else {
        logger.info("Connecting to AMQP API at " + Joiners.onCommaSpace.join(config.getAddresses()));
        this.connection = this.createConnectionFactory().newConnection(this.config.getAddresses().toArray(new Address[0]));
        this.channel = this.connection.createChannel();
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:11,代码来源:QueueClient.java

示例8: init

import com.rabbitmq.client.Address; //导入依赖的package包/类
@Override
public void init(AbstractConfiguration config, ApplicationListenerFactory factory) {
    try {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setUsername(config.getString("rabbitmq.userName", ConnectionFactory.DEFAULT_USER));
        cf.setPassword(config.getString("rabbitmq.password", ConnectionFactory.DEFAULT_PASS));
        cf.setVirtualHost(config.getString("rabbitmq.virtualHost", ConnectionFactory.DEFAULT_VHOST));
        cf.setAutomaticRecoveryEnabled(true);
        cf.setExceptionHandler(new RabbitMQExceptionHandler());
        this.conn = cf.newConnection(Address.parseAddresses(config.getString("rabbitmq.addresses")));
        this.channel = conn.createChannel();

        logger.trace("Initializing RabbitMQ application resources ...");

        APPLICATION_TOPIC = config.getString("communicator.application.topic");
        this.channel.exchangeDeclare(APPLICATION_TOPIC, "topic", true);

        logger.trace("Initializing RabbitMQ application consumer's workers ...");

        Channel consumerChan = this.conn.createChannel();
        consumerChan.queueDeclare(config.getString("rabbitmq.app.queueName"), true, false, true, null);
        consumerChan.queueBind(config.getString("rabbitmq.app.queueName"), APPLICATION_TOPIC, config.getString("rabbitmq.app.routingKey"));
        consumerChan.basicConsume(config.getString("rabbitmq.app.queueName"), true, new RabbitMQApplicationConsumer(consumerChan, factory.newListener()));

    } catch (IOException | TimeoutException e) {
        logger.error("Failed to connect to RabbitMQ servers", e);
        throw new IllegalStateException("Init RabbitMQ communicator failed");
    }
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:30,代码来源:RabbitMQApplicationCommunicator.java

示例9: prepare

import com.rabbitmq.client.Address; //导入依赖的package包/类
public synchronized void prepare() throws IOException, TimeoutException {
    if (rabbitMqChannelPool == null || rabbitMqChannelPool.isClosed()) {
        LOGGER.info("Creating RabbitMQ channel pool...");
        ConnectionFactory rabbitMqConnectionFactory = createConnectionFactory();
        if (rabbitMqConfig.hasAddresses()) {
            Address[] addresses = Address.parseAddresses(rabbitMqConfig.getAddresses());
            this.rabbitMqChannelFactory = new RabbitMqChannelFactory(rabbitMqConnectionFactory, addresses);
        } else {
            this.rabbitMqChannelFactory = new RabbitMqChannelFactory(rabbitMqConnectionFactory);
        }
        this.rabbitMqChannelPool = createRabbitMqChannelPool(rabbitMqChannelFactory);
        LOGGER.info("RabbitMQ channel pool was created");
    }
}
 
开发者ID:anderelate,项目名称:storm-rabbitmq,代码行数:15,代码来源:RabbitMqChannelProvider.java

示例10: prepareWithAddresses

import com.rabbitmq.client.Address; //导入依赖的package包/类
@Test
public void prepareWithAddresses() throws IOException, TimeoutException {
    String addresses = "10.189.21.119:8080,10.189.21.118:8181";
    RabbitMqConfig rabbitMqConfig = new RabbitMqConfigBuilder()
            .setAddresses(addresses)
            .build();
    RabbitMqChannelProvider rabbitMqChannelProvider = spy(new RabbitMqChannelProvider(rabbitMqConfig));
    doReturn(mockConnectionFactory).when(rabbitMqChannelProvider).createConnectionFactory();
    rabbitMqChannelProvider.prepare();
    verify(mockConnectionFactory, times(1)).newConnection(Address.parseAddresses(addresses));
}
 
开发者ID:anderelate,项目名称:storm-rabbitmq,代码行数:12,代码来源:RabbitMqChannelProviderTest.java

示例11: initAddresses

import com.rabbitmq.client.Address; //导入依赖的package包/类
/**
 *
 */
private void initAddresses(String hosts,int port) {
    String[] servers = hosts.split(",");
    addresses = new Address[servers.length];
    for(int i=0;i<servers.length;i++){
        addresses[i] = new Address(servers[i],port);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:11,代码来源:RabbitConnectionFactory.java

示例12: convertAddresses

import com.rabbitmq.client.Address; //导入依赖的package包/类
static List<Address> convertAddresses(String addresses) {
  String[] addressStrings = addresses.split(",");
  Address[] addressArray = new Address[addressStrings.length];
  for (int i = 0; i < addressStrings.length; i++) {
    String[] splitAddress = addressStrings[i].split(":");
    String host = splitAddress[0];
    Integer port = null;
    try {
      if (splitAddress.length == 2) port = Integer.parseInt(splitAddress[1]);
    } catch (NumberFormatException ignore) {
    }
    addressArray[i] = (port != null) ? new Address(host, port) : new Address(host);
  }
  return Arrays.asList(addressArray);
}
 
开发者ID:openzipkin,项目名称:zipkin-reporter-java,代码行数:16,代码来源:RabbitMQSender.java

示例13: addresses

import com.rabbitmq.client.Address; //导入依赖的package包/类
@Test public void addresses() {
  context = new XmlBeans(""
      + "<bean id=\"sender\" class=\"zipkin2.reporter.beans.RabbitMQSenderFactoryBean\">\n"
      + "  <property name=\"addresses\" value=\"localhost\"/>\n"
      + "</bean>"
  );

  assertThat(context.getBean("sender", RabbitMQSender.class))
      .extracting("addresses")
      .containsExactly(Arrays.asList(new Address("localhost")));
}
 
开发者ID:openzipkin,项目名称:zipkin-reporter-java,代码行数:12,代码来源:RabbitMQSenderFactoryBeanTest.java

示例14: setAddresses

import com.rabbitmq.client.Address; //导入依赖的package包/类
/**
 * If this option is set, camel-rabbitmq will try to create connection based on the setting of option addresses.
 * The addresses value is a string which looks like "server1:12345, server2:12345"
 */
public void setAddresses(String addresses) {
    Address[] addressArray = Address.parseAddresses(addresses);
    if (addressArray.length > 0) {
        this.addresses = addressArray;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:RabbitMQEndpoint.java

示例15: brokerEndpointAddressesSettings

import com.rabbitmq.client.Address; //导入依赖的package包/类
@Test
public void brokerEndpointAddressesSettings() throws Exception {
    RabbitMQEndpoint endpoint = context.getEndpoint("rabbitmq:localhost/exchange?addresses=server1:12345,server2:12345", RabbitMQEndpoint.class);
    assertEquals("Wrong size of endpoint addresses.", 2, endpoint.getAddresses().length);
    assertEquals("Get a wrong endpoint address.", new Address("server1", 12345), endpoint.getAddresses()[0]);
    assertEquals("Get a wrong endpoint address.", new Address("server2", 12345), endpoint.getAddresses()[1]);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:RabbitMQEndpointTest.java


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