本文整理匯總了Java中org.springframework.amqp.rabbit.connection.CachingConnectionFactory類的典型用法代碼示例。如果您正苦於以下問題:Java CachingConnectionFactory類的具體用法?Java CachingConnectionFactory怎麽用?Java CachingConnectionFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CachingConnectionFactory類屬於org.springframework.amqp.rabbit.connection包,在下文中一共展示了CachingConnectionFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDefaultRabbitConfiguration
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
@Test
public void testDefaultRabbitConfiguration() {
load(TestConfiguration.class);
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
RabbitMessagingTemplate messagingTemplate = this.context
.getBean(RabbitMessagingTemplate.class);
CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
assertThat(rabbitTemplate.getConnectionFactory()).isEqualTo(connectionFactory);
assertThat(getMandatory(rabbitTemplate)).isFalse();
assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
assertThat(amqpAdmin).isNotNull();
assertThat(connectionFactory.getHost()).isEqualTo("localhost");
assertThat(dfa.getPropertyValue("publisherConfirms")).isEqualTo(false);
assertThat(dfa.getPropertyValue("publisherReturns")).isEqualTo(false);
assertThat(this.context.containsBean("rabbitListenerContainerFactory"))
.as("Listener container factory should be created by default").isTrue();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:21,代碼來源:RabbitAutoConfigurationTests.java
示例2: testConnectionFactoryWithOverrides
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的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
示例3: rabbitConnectionFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的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
示例4: checkConnectionFactoryIsErrorCapable
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
private void checkConnectionFactoryIsErrorCapable() {
if (!(this.connectionFactory instanceof CachingConnectionFactory)) {
logger.warn("Unknown connection factory type, cannot determine error capabilities: "
+ this.connectionFactory.getClass());
}
else {
CachingConnectionFactory ccf = (CachingConnectionFactory) this.connectionFactory;
if (!ccf.isPublisherConfirms() && !ccf.isPublisherReturns()) {
logger.warn("Producer error channel is enabled, but the connection factory is not configured for "
+ "returns or confirms; the error channel will receive no messages");
}
else if (!ccf.isPublisherConfirms()) {
logger.info("Producer error channel is enabled, but the connection factory is only configured to "
+ "handle returned messages; negative acks will not be reported");
}
else if (!ccf.isPublisherReturns()) {
logger.info("Producer error channel is enabled, but the connection factory is only configured to "
+ "handle negatively acked messages; returned messages will not be reported");
}
}
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-rabbit,代碼行數:22,代碼來源:RabbitMessageChannelBinder.java
示例5: getAmqpConnectionFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的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;
}
示例6: testConnectionFactoryWithOverrides
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的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);
}
示例7: init
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
@PostConstruct
private void init() {
log.info("Initialization of RabbitConfiguration");
emsConnectionFactory = new CachingConnectionFactory();
((CachingConnectionFactory) emsConnectionFactory).setHost(brokerIp);
((CachingConnectionFactory) emsConnectionFactory).setPort(rabbitPort);
((CachingConnectionFactory) emsConnectionFactory).setUsername(emsRabbitUsername);
((CachingConnectionFactory) emsConnectionFactory).setPassword(emsRabbitPassword);
rabbitAdmin = new RabbitAdmin(emsConnectionFactory);
TopicExchange topicExchange = new TopicExchange("openbaton-exchange");
rabbitAdmin.declareExchange(topicExchange);
log.info("exchange declared");
queueName_emsRegistrator = "ems." + vnfmHelper.getVnfmEndpoint() + ".register";
rabbitAdmin.declareQueue(new Queue(queueName_emsRegistrator, durable, exclusive, autodelete));
}
示例8: rabbitConnectionFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
@Bean
public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config)
throws Exception {
RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean();
if (config.getHost() != null) {
factory.setHost(config.getHost());
factory.setPort(config.getPort());
}
if (config.getUsername() != null) {
factory.setUsername(config.getUsername());
}
if (config.getPassword() != null) {
factory.setPassword(config.getPassword());
}
if (config.getVirtualHost() != null) {
factory.setVirtualHost(config.getVirtualHost());
}
if (config.getRequestedHeartbeat() != null) {
factory.setRequestedHeartbeat(config.getRequestedHeartbeat());
}
RabbitProperties.Ssl ssl = config.getSsl();
if (ssl.isEnabled()) {
factory.setUseSSL(true);
factory.setKeyStore(ssl.getKeyStore());
factory.setKeyStorePassphrase(ssl.getKeyStorePassword());
factory.setTrustStore(ssl.getTrustStore());
factory.setTrustStorePassphrase(ssl.getTrustStorePassword());
}
factory.afterPropertiesSet();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
factory.getObject());
connectionFactory.setAddresses(config.getAddresses());
return connectionFactory;
}
示例9: testDefaultRabbitConfiguration
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
@Test
public void testDefaultRabbitConfiguration() {
load(TestConfiguration.class);
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
RabbitMessagingTemplate messagingTemplate = this.context
.getBean(RabbitMessagingTemplate.class);
CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class);
RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
assertEquals(connectionFactory, rabbitTemplate.getConnectionFactory());
assertEquals(rabbitTemplate, messagingTemplate.getRabbitTemplate());
assertNotNull(amqpAdmin);
assertEquals("localhost", connectionFactory.getHost());
assertTrue("Listener container factory should be created by default",
this.context.containsBean("rabbitListenerContainerFactory"));
}
示例10: rabbitConnectionFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的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;
}
示例11: rabbitConnectionFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的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;
}
示例12: rabbitConnectionFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
@Bean(name="rabbitMQConnectionFactory")
public ConnectionFactory rabbitConnectionFactory() {
CloudFactory cloudFactory = new CloudFactory();
Cloud cloud = cloudFactory.getCloud();
AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) cloud.getServiceInfo("activationAmqpBroker");
String serviceID = amqpServiceInfo.getId();
ConnectionFactory connectionFactory = cloud.getServiceConnector(serviceID, ConnectionFactory.class, null);
try{
LOGGER.info("Setting CachingConnectionFactory specific properties");
((CachingConnectionFactory)connectionFactory).setChannelCacheSize(channelCacheSize);
((CachingConnectionFactory)connectionFactory).setRequestedHeartBeat(requestedHeartbeat);
((CachingConnectionFactory)connectionFactory).setConnectionTimeout(connectionTimeout);
} catch (ClassCastException cce){
throw new TechnicalException("Cannot customize CachingConnectionFactory for rabbitConnectionFactory");
}
return connectionFactory;
}
示例13: connectionFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
@Bean
@DependsOn("amqpBroker")
CachingConnectionFactory connectionFactory() {
log.info("Creating connection factory for MQ broker...");
ConnectionFactory cf = new ConnectionFactory();
cf.setHost(hostname);
cf.setPort(port);
cf.setUsername(userName);
cf.setPassword(password);
cf.setVirtualHost(virtualHost);
cf.setAutomaticRecoveryEnabled(false);
if (useSSL) {
try {
cf.useSslProtocol();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
//TODO don't throw raw exceptions
throw new RuntimeException(e);
}
}
log.info("Connection factory created.");
return new CachingConnectionFactory(cf);
}
示例14: connectToBroker
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
/**
* Creates a new connection to an AMQP broker with the given information.
*/
private void connectToBroker()
{
if (this.objConnection == null)
{
this.objConnection = new CachingConnectionFactory();
String host = this.objResources.getConfiguration().getHost();
String addresses = "";
for (int port : this.objResources.getConfiguration().getPorts())
{
addresses = addresses + host + ":" + port + ",";
}
this.objConnection.setAddresses(addresses);
this.objConnection.setUsername(this.objResources.getConfiguration().getUsername());
this.objConnection.setPassword(this.objResources.getConfiguration().getPassword());
this.objConnection.setChannelCacheSize(25);
}
}
示例15: connectToBroker
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; //導入依賴的package包/類
/**
* Creates a new connection to an AMQP broker with the given information.
*/
private void connectToBroker()
{
if (this.objConnection == null)
{
this.objConnection = new CachingConnectionFactory();
Configuration config = this.objResources.getConfiguration();
String host = config.getHost();
String addresses = "";
for (int port : config.getPorts())
{
addresses = addresses + host + ":" + port + ", ";
}
this.objConnection.setAddresses(addresses);
this.objConnection.setUsername(config.getUsername());
this.objConnection.setPassword(config.getPassword());
this.objConnection.setChannelCacheSize(25);
}
}