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


Java ConnectionFactory類代碼示例

本文整理匯總了Java中org.springframework.amqp.rabbit.connection.ConnectionFactory的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionFactory類的具體用法?Java ConnectionFactory怎麽用?Java ConnectionFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: legacyPojoListener

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
public SimpleMessageListenerContainer legacyPojoListener(ConnectionFactory connectionFactory) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setQueueNames(MAPPED_QUEUE);
    MessageListenerAdapter messageListener = new MessageListenerAdapter(new Object() {

        @SuppressWarnings("unused")
        public void handleMessage(Object object) {
            System.out.println("Got a " + object);
            JsonApp.this.latch.countDown();
        }

    });
    Jackson2JsonMessageConverter jsonConverter = new Jackson2JsonMessageConverter();
    jsonConverter.setClassMapper(classMapper());
    messageListener.setMessageConverter(jsonConverter);
    container.setMessageListener(messageListener);
    return container;
}
 
開發者ID:laidu,項目名稱:java-learn,代碼行數:20,代碼來源:JsonApp.java

示例2: amqpChannelAdapter

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@ServiceActivator(inputChannel = Sink.INPUT)
@Bean
public MessageHandler amqpChannelAdapter(ConnectionFactory rabbitConnectionFactory) {
	AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(rabbitTemplate(rabbitConnectionFactory));
	DefaultAmqpHeaderMapper mapper = new DefaultAmqpHeaderMapper();
	mapper.setRequestHeaderNames(this.properties.getMappedRequestHeaders());
	handler.setHeaderMapper(mapper);
	handler.setDefaultDeliveryMode(this.properties.getPersistentDeliveryMode()
									? MessageDeliveryMode.PERSISTENT
									: MessageDeliveryMode.NON_PERSISTENT);
	if (this.properties.getExchangeExpression() == null) {
		handler.setExchangeName(this.properties.getExchange());
	}
	else {
		handler.setExpressionExchangeName(this.properties.getExchangeExpression());
	}
	if (this.properties.getRoutingKeyExpression() == null) {
		handler.setRoutingKey(this.properties.getRoutingKey());
	}
	else {
		handler.setExpressionRoutingKey(this.properties.getRoutingKeyExpression());
	}
	return handler;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:25,代碼來源:RabbitSinkConfiguration.java

示例3: getSimpleMessageListenerContainer

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
private SimpleMessageListenerContainer getSimpleMessageListenerContainer(
    ConnectionFactory connectionFactory,
    @Qualifier("listenerAdapter_vnfmCoreActions") MessageListenerAdapter listenerAdapter,
    String queueName_vnfmCoreActions,
    int minConcurrency,
    int maxConcurrency) {
  SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
  container.setConnectionFactory(connectionFactory);
  container.setQueueNames(queueName_vnfmCoreActions);
  if (minConcurrency <= 0 || maxConcurrency <= 0 || minConcurrency > maxConcurrency) {
    container.setConcurrentConsumers(5);
    container.setMaxConcurrentConsumers(15);
  } else {
    container.setConcurrentConsumers(minConcurrency);
    container.setMaxConcurrentConsumers(maxConcurrency);
  }
  container.setMessageListener(listenerAdapter);
  container.setErrorHandler(
      new ConditionalRejectingErrorHandler(new HandleJsonSyntaxExceptionStrategy()));
  return container;
}
 
開發者ID:openbaton,項目名稱:NFVO,代碼行數:22,代碼來源:RabbitConfiguration.java

示例4: testConnectionFactoryWithOverrides

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的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

示例5: rabbitConnectionFactory

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
/**
 * Creates a {@link ConnectionFactory} using the singleton service connector.
 * @param cloud {@link Cloud} instance to be used for accessing services.
 * @param connectorConfigObjectProvider the {@link ObjectProvider} for the
 * {@link RabbitConnectionFactoryConfig}.
 * @return the {@link ConnectionFactory} used by the binder.
 */
@Bean
@Primary
ConnectionFactory rabbitConnectionFactory(Cloud cloud,
		ObjectProvider<RabbitConnectionFactoryConfig> connectorConfigObjectProvider,
		ConfigurableApplicationContext applicationContext,
		RabbitProperties rabbitProperties) throws Exception {

	ConnectionFactory connectionFactory = cloud.getSingletonServiceConnector(ConnectionFactory.class,
			connectorConfigObjectProvider.getIfUnique());

	configureCachingConnectionFactory((CachingConnectionFactory) connectionFactory,
			applicationContext, rabbitProperties);

	return connectionFactory;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-rabbit,代碼行數:23,代碼來源:RabbitServiceAutoConfiguration.java

示例6: testParentConnectionFactoryInheritedIfOverridden

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Test
public void testParentConnectionFactoryInheritedIfOverridden() {
	context = new SpringApplicationBuilder(SimpleProcessor.class, ConnectionFactoryConfiguration.class)
			.web(WebApplicationType.NONE)
			.run("--server.port=0");
	BinderFactory binderFactory = context.getBean(BinderFactory.class);
	Binder<?, ?, ?> binder = binderFactory.getBinder(null, MessageChannel.class);
	assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
	DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
	ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
			.getPropertyValue("connectionFactory");
	assertThat(binderConnectionFactory).isSameAs(MOCK_CONNECTION_FACTORY);
	ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
	assertThat(binderConnectionFactory).isSameAs(connectionFactory);
	CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
			CompositeHealthIndicator.class);
	assertThat(bindersHealthIndicator).isNotNull();
	DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
	@SuppressWarnings("unchecked")
	Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
			.getPropertyValue("indicators");
	assertThat(healthIndicators).containsKey("rabbit");
	// mock connection factory behaves as if down
	assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo(Status.DOWN);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-rabbit,代碼行數:26,代碼來源:RabbitBinderModuleTests.java

示例7: amqpChannelAdapter

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@ServiceActivator(inputChannel = Sink.INPUT)
@Bean
public MessageHandler amqpChannelAdapter(ConnectionFactory rabbitConnectionFactory) {
	AmqpOutboundEndpointSpec handler = Amqp.outboundAdapter(rabbitTemplate(rabbitConnectionFactory))
			.mappedRequestHeaders(properties.getMappedRequestHeaders())
			.defaultDeliveryMode(properties.getPersistentDeliveryMode() ? MessageDeliveryMode.PERSISTENT
					: MessageDeliveryMode.NON_PERSISTENT);

	Expression exchangeExpression = this.properties.getExchangeExpression();
	if (exchangeExpression != null) {
		handler.exchangeNameExpression(exchangeExpression);
	}
	else {
		handler.exchangeName(this.properties.getExchange());
	}

	Expression routingKeyExpression = this.properties.getRoutingKeyExpression();
	if (routingKeyExpression != null) {
		handler.routingKeyExpression(routingKeyExpression);
	}
	else {
		handler.routingKey(this.properties.getRoutingKey());
	}

	return handler.get();
}
 
開發者ID:spring-cloud-stream-app-starters,項目名稱:rabbit,代碼行數:27,代碼來源:RabbitSinkConfiguration.java

示例8: getAmqpConnectionFactory

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
ConnectionFactory getAmqpConnectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
    LOGGER.info("Creating AMQP connection factory on host {}:{}", host, port);
    if (!username.isEmpty()) {
        connectionFactory.setUsername(username);
        LOGGER.info("Logging to AMQP with username ", username);
    } else {
        LOGGER.warn("Logging to AMQP with NO username");
    }
    if (!password.isEmpty()) {
        connectionFactory.setPassword(password);
        LOGGER.info("Logging to AMQP with password {}", password.replaceAll(".", "*"));
    } else {
        LOGGER.warn("Logging to AMQP with NO password");
    }
    return connectionFactory;
}
 
開發者ID:Byteflair,項目名稱:resthooks,代碼行數:19,代碼來源:AmqpConfig.java

示例9: testConnectionFactoryWithOverrides

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的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);
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:17,代碼來源:RabbitAutoConfigurationTests.java

示例10: amqpReplyFlow

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
IntegrationFlow amqpReplyFlow(ConnectionFactory rabbitConnectionFactory,
                              UserManager ftpUserManager) {
    return IntegrationFlows.from(Amqp.inboundGateway(rabbitConnectionFactory, this.ftpRequests)
            .messageConverter(new Jackson2JsonMessageConverter()))
            .transform(String.class, new GenericTransformer<String, String>() {
                @Override
                public String transform(String source) {
                    try {
                        Map<String, String> map = toMap(source);
                        String ws = map.get("workspace");
                        String usr = map.get("user");
                        String password = UUID.randomUUID().toString();
                        FtpUser user = new FtpUser(ws, usr, password, true);
                        ftpUserManager.save(user);
                        String ftpUri = buildFtpConnectionString(host, port, user);
                        log.info("registering: workspace: " + ws + ", " + "user: " + usr + ", ftp URI: " + ftpUri);
                        return ftpUri;
                    } catch (FtpException e) {
                        throw new RuntimeException(e);
                    }
                }
            }).get();
}
 
開發者ID:joshlong,項目名稱:cloudfoundry-ftp-service-broker,代碼行數:25,代碼來源:Application.java

示例11: rabbitListenerContainerFactory

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
		ConnectionFactory connectionFactory, RabbitProperties config) {
	SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
	factory.setConnectionFactory(connectionFactory);
	Listener listenerConfig = config.getListener();
	factory.setAutoStartup(listenerConfig.isAutoStartup());
	if (listenerConfig.getAcknowledgeMode() != null) {
		factory.setAcknowledgeMode(listenerConfig.getAcknowledgeMode());
	}
	if (listenerConfig.getConcurrency() != null) {
		factory.setConcurrentConsumers(listenerConfig.getConcurrency());
	}
	if (listenerConfig.getMaxConcurrency() != null) {
		factory.setMaxConcurrentConsumers(listenerConfig.getMaxConcurrency());
	}
	if (listenerConfig.getPrefetch() != null) {
		factory.setPrefetchCount(listenerConfig.getPrefetch());
	}
	if (listenerConfig.getTransactionSize() != null) {
		factory.setTxSize(listenerConfig.getTransactionSize());
	}
	return factory;
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:26,代碼來源:RabbitAnnotationDrivenConfiguration.java

示例12: rabbitConnectionFactory

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
ConnectionFactory rabbitConnectionFactory(final RabbitMqSetupService rabbitmqSetupService) {
    final CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setHost(rabbitmqSetupService.getHostname());
    factory.setPort(5672);
    factory.setUsername(rabbitmqSetupService.getUsername());
    factory.setPassword(rabbitmqSetupService.getPassword());
    try {
        factory.setVirtualHost(rabbitmqSetupService.createVirtualHost());
        // All exception are catched. The BrokerRunning decide if the
        // test should break or not
    } catch (@SuppressWarnings("squid:S2221") final Exception e) {
        Throwables.propagateIfInstanceOf(e, AlivenessException.class);
        LOG.error("Cannot create virtual host {}", e.getMessage());
    }
    return factory;
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:18,代碼來源:AmqpTestConfiguration.java

示例13: container_logDispatcher

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
SimpleMessageListenerContainer container_logDispatcher(
    ConnectionFactory connectionFactory,
    @Qualifier("listenerAdapter_logDispatch") MessageListenerAdapter listenerAdapter) {
  if (listenerAdapter != null) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames(queueName_logDispatch);
    if (minConcurrency <= 0 || maxConcurrency <= 0 || minConcurrency > maxConcurrency) {
      container.setConcurrentConsumers(5);
      container.setMaxConcurrentConsumers(15);
    } else {
      container.setConcurrentConsumers(minConcurrency);
      container.setMaxConcurrentConsumers(maxConcurrency);
    }
    container.setMessageListener(listenerAdapter);
    return container;
  } else return null;
}
 
開發者ID:openbaton,項目名稱:openbaton-libs,代碼行數:20,代碼來源:RabbitConfiguration.java

示例14: container_eventRegister

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
SimpleMessageListenerContainer container_eventRegister(
    ConnectionFactory connectionFactory,
    @Qualifier("listenerAdapter_nfvoGenericActions") MessageListenerAdapter listenerAdapter) {
  SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
  container.setConnectionFactory(connectionFactory);
  container.setQueueNames(queueName_nfvoGenericActions);
  if (minConcurrency <= 0 || maxConcurrency <= 0 || minConcurrency > maxConcurrency) {
    container.setConcurrentConsumers(5);
    container.setMaxConcurrentConsumers(15);
  } else {
    container.setConcurrentConsumers(minConcurrency);
    container.setMaxConcurrentConsumers(maxConcurrency);
  }
  container.setMessageListener(listenerAdapter);
  return container;
}
 
開發者ID:openbaton,項目名稱:openbaton-libs,代碼行數:18,代碼來源:RabbitConfiguration.java

示例15: rabbitConnectionFactory

import org.springframework.amqp.rabbit.connection.ConnectionFactory; //導入依賴的package包/類
@Bean
public ConnectionFactory rabbitConnectionFactory() {
	com.rabbitmq.client.ConnectionFactory cf = new com.rabbitmq.client.ConnectionFactory();
	cf.setNetworkRecoveryInterval(rabbitNetworkRecoveryInterval);
	cf.setRequestedHeartbeat(rabbitHeartbeatInterval);
	
	CachingConnectionFactory connectionFactory = new CachingConnectionFactory(cf);
	connectionFactory.setVirtualHost(rabbitVirtualHost);
	connectionFactory.setAddresses(rabbitAddresses);
	connectionFactory.setUsername(rabbitUsername);
    connectionFactory.setPassword(rabbitPassword);
    connectionFactory.setPublisherConfirms(publisherConfirms);
    connectionFactory.setConnectionTimeout(rabbitConnectionTimeout);
    connectionFactory.setChannelCheckoutTimeout(rabbitChannelCheckoutTimeout);
    connectionFactory.setCloseTimeout(rabbitCloseTimeout);
    return connectionFactory;
}
 
開發者ID:sshcherbakov,項目名稱:cf-service-tester,代碼行數:18,代碼來源:StandaloneConfig.java


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