title: Google Pub/Sub - Multiple subscriptions to same topic to reduce load via REST API?
body: <p>There will be one publisher to one topic.  Let's say 1000s of messages/sec.</p>
  
  <p>Can I load balance these by having multiple endpoints to receive the messages?</p>
  
  <p>This is what I want to do: 
  (Does the REST API for Google Pub/Sub allow this?)</p>
  
  <p>JMS 2.0 provides a solution. You can create a "shared" nondurable subscription using a new method: createSharedConsumer. This method is available both on Session (for applications using the classic API) and on JMSContext (for applications using the simplified API). Since the two JVMs need to be able to identify the subscription that they need to share, they need to supply a name to identify the shared subscription, as shown in Listing 2.</p>
  
  <pre><code>private void createSharedConsumer(ConnectionFactory connectionFactory, Topic topic) throws JMSException {
     Connection connection = connectionFactory.createConnection();
     Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
     MessageConsumer messageConsumer = session.createSharedConsumer(topic,"mySubscription");
     connection.start();
     Message message = messageConsumer.receive(10000);
     while (message != null) {
        System.out.println("Message received: " + ((TextMessage) message).getText());
        message = messageConsumer.receive(10000);
     }
     connection.close();
  }
  </code></pre>
  
  <p>Listing 2</p>
  
  <p>If you run the code in Listing 2 in two separate JVMs, each message sent to the topic will be delivered to one or the other of the two consumers. This allows them to share the work of processing messages from the subscription.</p>
  
  <p><a href="http://www.oracle.com/technetwork/articles/java/jms2messaging-1954190.html" rel="noreferrer">http://www.oracle.com/technetwork/articles/java/jms2messaging-1954190.html</a></p>
  
  <p>JMS 2.0 specification describes the concept of Shared Subscription where more than one subscriber/consumer share (a.k.a load balance) messages published on a topic. All consumers use same subscription id.</p>