Closed icanfly closed 8 years ago
There is a huge difference between Consumers and Producers. With Producers you want to control which nodes are used for a specific topic but as a Consumer you really don't have a choice because you want to consume the messages from all nodes of a specific topic. If you think that Producers should use lookupd then you can easily bolt it on yourself.
Why the implementation of producer not apply consumer model, get nsqd server address by lookup lookupd servers, then establish a connection for message sending, and decide which nsqd to send a message by scheduling lookup lookupd servers
like this: ` public NSQConsumer(final NSQLookup lookup, final String topic, final String channel, final NSQMessageCallback callback) { this(lookup, topic, channel, callback, new NSQConfig()); }
` but Producer has initialized hardly like this:
` public class NSQProducer { private Set addresses = Sets.newConcurrentHashSet();
...
protected Connection getConnection() throws NoConnectionsException { int c = 0; while (c < connectionRetries) { ServerAddress[] serverAddresses = addresses.toArray(new ServerAddress[addresses.size()]); if (serverAddresses.length != 0) { try { return pool.borrowObject(serverAddresses[roundRobinCount++ % serverAddresses.length]); } catch (NoSuchElementException e) { try { Thread.sleep(1000); } catch (InterruptedException ix) { throw new NoConnectionsException("Could not acquire a connection to a server", ix); } } catch (Exception ex) { throw new NoConnectionsException("Could not acquire a connection to a server", ex); } } } throw new IllegalStateException("No server configured for producer"); }
`
I think it's good for Increase/Decrease number of nsqd servers.