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


Java CachingConnectionFactory类代码示例

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


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

示例1: validateBytesConvertedToBytesMessageOnSend

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Test
public void validateBytesConvertedToBytesMessageOnSend() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    publisher.publish(destinationName, "hellomq".getBytes());

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    byte[] bytes = new byte[7];
    ((BytesMessage) receivedMessage).readBytes(bytes);
    assertEquals("hellomq", new String(bytes));

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:17,代码来源:JMSPublisherConsumerTest.java

示例2: checkRabbitMQAMQPProtocol

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
public String checkRabbitMQAMQPProtocol(String messageAsString,
                                        String url,
                                        String user,
                                        String password,
                                        String vhost) throws Exception {
    org.springframework.amqp.rabbit.connection.CachingConnectionFactory cf =
            new org.springframework.amqp.rabbit.connection.CachingConnectionFactory();
    URL formattedUrl = new URL("http://" + url);
    cf.setHost(formattedUrl.getHost());
    cf.setPort(formattedUrl.getPort());
    cf.setUsername(user);
    cf.setPassword(password);
    cf.setVirtualHost(vhost);
    RabbitAdmin admin = new RabbitAdmin(cf);
    org.springframework.amqp.core.Queue queue = new org.springframework.amqp.core.Queue("myQueue");
    admin.declareQueue(queue);
    TopicExchange exchange = new TopicExchange("myExchange");
    admin.declareExchange(exchange);
    admin.declareBinding(
            BindingBuilder.bind(queue).to(exchange).with("foo.*"));
    RabbitTemplate template = new RabbitTemplate(cf);
    template.convertAndSend("myExchange", "foo.bar", messageAsString);
    String receivedMessage = template.receiveAndConvert("myQueue").toString();
    return receivedMessage;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:26,代码来源:CheckBrokerConnectionUtils.java

示例3: buildTargetResource

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
/**
 * This method essentially performs initialization of this Processor by
 * obtaining an instance of the {@link ConnectionFactory} from the
 * {@link JMSConnectionFactoryProvider} (ControllerService) and performing a
 * series of {@link ConnectionFactory} adaptations which eventually results
 * in an instance of the {@link CachingConnectionFactory} used to construct
 * {@link JmsTemplate} used by this Processor.
 */
private void buildTargetResource(ProcessContext context) {
    if (this.targetResource == null) {
        JMSConnectionFactoryProviderDefinition cfProvider = context.getProperty(CF_SERVICE).asControllerService(JMSConnectionFactoryProviderDefinition.class);
        ConnectionFactory connectionFactory = cfProvider.getConnectionFactory();

        UserCredentialsConnectionFactoryAdapter cfCredentialsAdapter = new UserCredentialsConnectionFactoryAdapter();
        cfCredentialsAdapter.setTargetConnectionFactory(connectionFactory);
        cfCredentialsAdapter.setUsername(context.getProperty(USER).getValue());
        cfCredentialsAdapter.setPassword(context.getProperty(PASSWORD).getValue());

        this.cachingConnectionFactory = new CachingConnectionFactory(cfCredentialsAdapter);
        this.cachingConnectionFactory.setSessionCacheSize(Integer.parseInt(context.getProperty(SESSION_CACHE_SIZE).getValue()));

        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(this.cachingConnectionFactory);
        jmsTemplate.setPubSubDomain(TOPIC.equals(context.getProperty(DESTINATION_TYPE).getValue()));

        // set of properties that may be good candidates for exposure via configuration
        jmsTemplate.setReceiveTimeout(1000);

        this.targetResource = this.finishBuildingTargetResource(jmsTemplate, context);
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:32,代码来源:AbstractJMSProcessor.java

示例4: validateBytesConvertedToBytesMessageOnSendOverJNDI

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Test
public void validateBytesConvertedToBytesMessageOnSendOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    publisher.publish(destinationName, "hellomq".getBytes());

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    byte[] bytes = new byte[7];
    ((BytesMessage) receivedMessage).readBytes(bytes);
    assertEquals("hellomq", new String(bytes));

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:17,代码来源:JMSPublisherConsumerTest.java

示例5: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    Map<String, String> flowFileAttributes = new HashMap<>();
    flowFileAttributes.put("foo", "foo");
    flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
    publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    assertEquals("foo", receivedMessage.getStringProperty("foo"));
    assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
    assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例6: validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Test
public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    Map<String, String> flowFileAttributes = new HashMap<>();
    flowFileAttributes.put("foo", "foo");
    flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic");
    publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes);

    Message receivedMessage = jmsTemplate.receive(destinationName);
    assertTrue(receivedMessage instanceof BytesMessage);
    assertEquals("foo", receivedMessage.getStringProperty("foo"));
    assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic);
    assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:20,代码来源:JMSPublisherConsumerTest.java

示例7: validateFailOnUnsupportedMessageTypeOverJNDI

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
public void validateFailOnUnsupportedMessageTypeOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:24,代码来源:JMSPublisherConsumerTest.java

示例8: validateFailOnUnsupportedMessageType

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
/**
 * At the moment the only two supported message types are TextMessage and
 * BytesMessage which is sufficient for the type if JMS use cases NiFi is
 * used. The may change to the point where all message types are supported
 * at which point this test will no be longer required.
 */
@Test(expected = IllegalStateException.class)
public void validateFailOnUnsupportedMessageType() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
开发者ID:SolaceLabs,项目名称:solace-integration-guides,代码行数:31,代码来源:JMSPublisherConsumerTest.java

示例9: cachingConnectionFactory

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Bean
public CachingConnectionFactory cachingConnectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setCacheConsumers(true);
    connectionFactory.setReconnectOnException(true);
    connectionFactory.setTargetConnectionFactory(connectionFactory());
    return connectionFactory;
}
 
开发者ID:przodownikR1,项目名称:springBatchJmsKata,代码行数:9,代码来源:ActiveMQConfig.java

示例10: sendMsg

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
public void sendMsg(Destination destination, final MsgEntity msgEntity) {
	ApplicationContext context = new ClassPathXmlApplicationContext(
			"applicationContext.xml");
	CachingConnectionFactory connectionFactory = (CachingConnectionFactory) context
			.getBean("cachingConnectionFactory");
	JmsTemplate jmsTemplate = new JmsTemplate();
	jmsTemplate.setDefaultDestination(destination);
	jmsTemplate.setConnectionFactory(connectionFactory);
	jmsTemplate.setReceiveTimeout(100000);
	jmsTemplate.setPubSubDomain(true);
	jmsTemplate.send(destination, new MessageCreator() {

		public Message createMessage(Session session) throws JMSException {
			Gson gson = new Gson();
			String msg = gson.toJson(msgEntity);
			return session.createTextMessage(msg);
		}
	});
	logger.info("push String:" + new Gson().toJson(msgEntity));
	try {
		logger.info("destination:" + ((Topic) destination).getTopicName());
	} catch (JMSException e) {
		e.printStackTrace();
	}
}
 
开发者ID:Martin404,项目名称:jmsRestful,代码行数:26,代码来源:ActiveMQProducerServiceImpl.java

示例11: validateConsumeWithCustomHeadersAndProperties

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Test
public void validateConsumeWithCustomHeadersAndProperties() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage("hello from the other side");
            message.setStringProperty("foo", "foo");
            message.setBooleanProperty("bar", false);
            message.setJMSReplyTo(session.createQueue("fooQueue"));
            return message;
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    final AtomicBoolean callbackInvoked = new AtomicBoolean();
    consumer.consume(destinationName, new ConsumerCallback() {
        @Override
        public void accept(JMSResponse response) {
            callbackInvoked.set(true);
            assertEquals("hello from the other side", new String(response.getMessageBody()));
            assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO));
            assertEquals("foo", response.getMessageProperties().get("foo"));
            assertEquals("false", response.getMessageProperties().get("bar"));
        }
    });
    assertTrue(callbackInvoked.get());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:33,代码来源:JMSPublisherConsumerTest.java

示例12: validateSuccessfulConsumeAndTransferToSuccess

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Test
public void validateSuccessfulConsumeAndTransferToSuccess() throws Exception {
    final String destinationName = "cooQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
    JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    final Map<String, String> senderAttributes = new HashMap<>();
    senderAttributes.put("filename", "message.txt");
    senderAttributes.put("attribute_from_sender", "some value");
    sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes);
    TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS());
    JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
    when(cs.getIdentifier()).thenReturn("cfProvider");
    when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
    runner.addControllerService("cfProvider", cs);
    runner.enableControllerService(cs);

    runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
    runner.setProperty(ConsumeJMS.DESTINATION, destinationName);
    runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
    runner.run(1, false);
    //
    final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
    assertNotNull(successFF);
    successFF.assertAttributeExists(JmsHeaders.DESTINATION);
    successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName);
    successFF.assertAttributeExists("filename");
    successFF.assertAttributeEquals("filename", "message.txt");
    successFF.assertAttributeExists("attribute_from_sender");
    successFF.assertAttributeEquals("attribute_from_sender", "some value");
    successFF.assertContentEquals("Hey dude!".getBytes());
    String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME);
    assertNotNull(sourceDestination);

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:36,代码来源:ConsumeJMSTest.java

示例13: connectionFactory

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Bean
public ConnectionFactory connectionFactory() {
    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerUrl);

    CachingConnectionFactory bean = new CachingConnectionFactory(activeMQConnectionFactory);
    bean.setSessionCacheSize(sessionCacheSize);
    return bean;
}
 
开发者ID:EsikAntony,项目名称:camunda-task-dispatcher,代码行数:9,代码来源:JmsExternalTaskCompleterConfig.java

示例14: receiverConnectionFactory

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
@Bean
public ConnectionFactory receiverConnectionFactory() {
    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerUrl);

    CachingConnectionFactory bean = new CachingConnectionFactory(activeMQConnectionFactory);
    bean.setSessionCacheSize(sessionCacheSize);
    return bean;
}
 
开发者ID:EsikAntony,项目名称:camunda-task-dispatcher,代码行数:9,代码来源:JmsExternalTaskReceiverConfig.java

示例15: checkActiveMQJMSProtocol

import org.springframework.jms.connection.CachingConnectionFactory; //导入依赖的package包/类
public String checkActiveMQJMSProtocol(String messageAsString,
                                       String url) throws JMSException {
    ActiveMQConnectionFactory activeMQConnectionFactory =
            new ActiveMQConnectionFactory(String.format("tcp://%s", url));
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(activeMQConnectionFactory);
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    Destination destination = new ActiveMQQueue("myQueue");
    jmsTemplate.setDefaultDestination(destination);
    jmsTemplate.send(destination, t -> {
        TextMessage message = t.createTextMessage(messageAsString);
        return message;
    });
    TextMessage receivedMessage = (TextMessage) jmsTemplate.receive(destination);
    return receivedMessage.getText();
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:16,代码来源:CheckBrokerConnectionUtils.java


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