本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}