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

The following examples show how to use org.springframework.jms.core.JmsTemplate#setPubSubDomain() . 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: 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 4
Source File: ConsumeJMSManualTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void send(MessageCreator messageCreator) throws Exception {
    final String  destinationName = "TEST";

    ConnectionFactory activeMqConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    final ConnectionFactory connectionFactory = new CachingConnectionFactory(activeMqConnectionFactory);

    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.setPubSubDomain(false);
    jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    jmsTemplate.setReceiveTimeout(10L);

    try {
        JMSPublisher sender = new JMSPublisher((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class));

        sender.jmsTemplate.send(destinationName, messageCreator);
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
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: ProducerConfiguration.java    From solace-samples-cloudfoundry-java with Apache License 2.0 5 votes vote down vote up
@Bean
public JmsTemplate jmsTemplate() {
	CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory);
	JmsTemplate jmst = new JmsTemplate(ccf);
	jmst.setPubSubDomain(true);	// This sample is publishing to topics
	return jmst;
}
 
Example 7
Source File: JndiProducerConfiguration.java    From solace-samples-cloudfoundry-java with Apache License 2.0 5 votes vote down vote up
@Bean
public JmsTemplate producerJmsTemplate() {
	JmsTemplate jt = new JmsTemplate(cachingConnectionFactory());
	jt.setDeliveryPersistent(true);
	jt.setDestinationResolver(producerJndiDestinationResolver());
	jt.setPubSubDomain(true);	// This sample is publishing to topics
	return jt;
}
 
Example 8
Source File: EventRegistryJmsConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
    JmsTemplate template = new JmsTemplate(connectionFactory);

    template.setPubSubDomain(false);

    return template;
}
 
Example 9
Source File: ArtemisConfig.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public JmsTemplate jmsTopicTemplate( ConnectionFactory connectionFactory, NameDestinationResolver nameDestinationResolver )
{
    JmsTemplate template = new JmsTemplate( connectionFactory );
    template.setDeliveryMode( DeliveryMode.NON_PERSISTENT );
    template.setDestinationResolver( nameDestinationResolver );
    // set to true, since we only use topics and we want to resolve names to topic destination
    template.setPubSubDomain( true );

    return template;
}
 
Example 10
Source File: ArtemisConfig.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public JmsTemplate jmsQueueTemplate( ConnectionFactory connectionFactory, NameDestinationResolver nameDestinationResolver )
{
    JmsTemplate template = new JmsTemplate( connectionFactory );
    template.setDeliveryMode( DeliveryMode.PERSISTENT );
    template.setDestinationResolver( nameDestinationResolver );
    template.setPubSubDomain( false );

    return template;
}
 
Example 11
Source File: CommonTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
static JmsTemplate buildJmsTemplateForDestination(boolean pubSub) {
    ConnectionFactory activeMqConnectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    final ConnectionFactory connectionFactory = new CachingConnectionFactory(activeMqConnectionFactory);

    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.setPubSubDomain(pubSub);
    jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    jmsTemplate.setReceiveTimeout(10L);
    return jmsTemplate;
}
 
Example 12
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 13
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 14
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 15
Source File: ActiveMQAutoConfiguration.java    From mykit-delay with Apache License 2.0 4 votes vote down vote up
@Bean
public JmsTemplate jmsQueueTemplate(){
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
    jmsTemplate.setPubSubDomain(properties.isQueue_pub_sub_domain());
    return jmsTemplate;
}
 
Example 16
Source File: ActiveMQAutoConfiguration.java    From mykit-delay with Apache License 2.0 4 votes vote down vote up
@Bean
public JmsTemplate jmsTopicTemplate(){
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
    jmsTemplate.setPubSubDomain(properties.isTopic_pub_sub_domain());
    return jmsTemplate;
}