Java Code Examples for org.springframework.jms.core.JmsTemplate#setConnectionFactory()

The following examples show how to use org.springframework.jms.core.JmsTemplate#setConnectionFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJMSProcessor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: AbstractJMSProcessor.java    From solace-integration-guides with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 3
Source File: JmsContainerManagerTest.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
  public void setUp() throws Exception {
    mockProcessCache = EasyMock.createMock(ProcessCache.class);
    mockListener = EasyMock.createMock(SessionAwareMessageListener.class);
    mockClusterCache = EasyMock.createMock(ClusterCache.class);

    jmsSender = new ActiveJmsSender();
    JmsTemplate template = new JmsTemplate();
    template.setConnectionFactory(daqInConnectionFactory);
    template.setTimeToLive(60000);
    jmsSender.setJmsTemplate(template);

//    jmsContainerManager = new JmsContainerManagerImpl(mockProcessCache, daqInConnectionFactory, mockListener, mockClusterCache, new StandardEnvironment());
//    jmsContainerManager.setConsumersInitial(1);
//    jmsContainerManager.setConsumersMax(1);
//    jmsContainerManager.setNbExecutorThreads(2);
//    jmsContainerManager.setIdleTaskExecutionLimit(1);
//    jmsContainerManager.setMaxMessages(1);
//    jmsContainerManager.setReceiveTimeout(100);
//    jmsContainerManager.setJmsUpdateQueueTrunk(testTrunkName);
//    jmsContainerManager.setSessionTransacted(true);
//    jmsContainerManager.setUpdateWarmUpSeconds(60);
  }
 
Example 4
Source File: AbstractJMSProcessor.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 T buildTargetResource(ProcessContext context) {
    final ConnectionFactory connectionFactory = connectionFactoryProvider.getConnectionFactory();

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

    final CachingConnectionFactory cachingFactory = new CachingConnectionFactory(cfCredentialsAdapter);
    setClientId(context, cachingFactory);

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

    return finishBuildingJmsWorker(cachingFactory, jmsTemplate, context);
}
 
Example 5
Source File: UserRepoPublisher.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void execute(UserRepo userRepo) {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", Long.toString(userRepo.getId()));
    map.put("code", userRepo.getCode());
    map.put("name", userRepo.getName());

    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(connectionFactory);
    jmsTemplate.setPubSubDomain(true);

    try {
        jmsTemplate.convertAndSend(destinationName, jsonMapper.toJson(map));
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    }
}
 
Example 6
Source File: ActiveMqConfig.java    From roncoo-pay with Apache License 2.0 5 votes vote down vote up
/**
 * 队列模板
 *
 * @param singleConnectionFactory 连接工厂
 * @return 队列模板
 */
@Bean(name = "jmsTemplate")
public JmsTemplate jmsTemplate(@Qualifier("connectionFactory") SingleConnectionFactory singleConnectionFactory) {
    JmsTemplate notifyJmsTemplate = new JmsTemplate();
    notifyJmsTemplate.setConnectionFactory(singleConnectionFactory);
    notifyJmsTemplate.setDefaultDestinationName(orderQueryDestinationName);
    return notifyJmsTemplate;
}
 
Example 7
Source File: ResourcePublisherImpl.java    From lemon with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void afterPropertiesSet() {
    Assert.notNull(connectionFactory);
    jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(connectionFactory);
    jmsTemplate.setPubSubDomain(true);
}
 
Example 8
Source File: UserPublisher.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void sendNotification(String destinationName, Object object) {
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(connectionFactory);
    jmsTemplate.setPubSubDomain(true);

    try {
        jmsTemplate.convertAndSend(destinationName,
                jsonMapper.toJson(object));
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    }
}
 
Example 9
Source File: UserPublisher.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void sendSynchronization(String destinationName, Object object) {
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(connectionFactory);
    jmsTemplate.setPubSubDomain(false);

    try {
        jmsTemplate.convertAndSend(destinationName,
                jsonMapper.toJson(object));
    } catch (IOException ex) {
        logger.error(ex.getMessage());
    }
}
 
Example 10
Source File: ApplicationConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public JmsTemplate jmsTemplate() {
    JmsTemplate template = new JmsTemplate(connectionFactory());
    template.setConnectionFactory(connectionFactory());
    return template;
}