Paul Gregoire
Paul Gregoire

Reputation: 9793

Is it possible for a JMS topic to have multiple publishers?

From what I've read so-far, a JMS Topic is 1-to-Many and I wonder if its possible to support Many-to-Many using a topic. Consider a topic called "Reports" with multiple services spread out across an enterprise needing to publish scheduled reports. Having multiple publishers would alleviate the need to subscribe interested applications to a topic for each of the reporting services.

Upvotes: 1

Views: 3576

Answers (3)

ag112
ag112

Reputation: 5697

@Mondain: yes, very much possible. A practical example would be live stock market price feed provided by multiple sources and those feed consumed by multiple channels.

Upvotes: 4

Paul
Paul

Reputation: 1873

You can do something like this, and call CreateMessageProducer to create a new instance of producer anywhere in your application.

  public ActiveMqProducer(string activeMqServiceUrl)
  {  
        _activeMqServiceUrl = activeMqServiceUrl; 

        IConnectionFactory factory = new ConnectionFactory(new Uri(_activeMqServiceUrl));

        _activeMqConnection = factory.CreateConnection();

        _activeMqSession = _activeMqConnection.CreateSession(AcknowledgementMode.Transactional);

        _activeMqConnection.Start();
  }

  private IMessageProducer CreateMessageProducer(string mqTopicName)
  {
        ITopic destination = SessionUtil.GetTopic(_activeMqSession, mqTopicName);
        var producer = _activeMqSession.CreateProducer(destination);
        return producer;
  }

Upvotes: 1

Massimo Zerbini
Massimo Zerbini

Reputation: 3191

Yes, you can create many TopicPublisher from your TopicSession, and many applications can connect the same Topic using TopicPublisher or TopicSubscriber.

Upvotes: 3

Related Questions