@Override public ConsumerFactory get() { if(typeDictionary == null) { // Thread safety: no need for volatile / synchronization - it doesn't hurt much if the TypeDictionary is created multiple times. ReflectionTypeDictionaryFactory dictionaryFactory = new ReflectionTypeDictionaryFactory(injector); typeDictionary = dictionaryFactory.createFromClasspath(); } return new ConsumerFactory(serviceProperties, typeDictionary, tracer, metricBuilderFactory); } }
private <T extends com.google.protobuf.Message> ConsumerFactory consumerFactoryWithHandler(ServiceProperties serviceProperties, Class<T> messageType, MessageHandler<T> handler) { TypeDictionary typeDictionary = new TypeDictionary(); ReflectionTypeDictionaryFactory reflectionCruft = new ReflectionTypeDictionaryFactory(null); typeDictionary.putAllParsers(reflectionCruft.populateParsersFromClasspath()); typeDictionary.putHandler(MessageType.of(messageType), handler); ConsumerFactory consumerFactory = new ConsumerFactory(serviceProperties, typeDictionary, null, null); return consumerFactory; }
private <T extends com.google.protobuf.Message> ConsumerFactory consumerFactoryWithHandler(ServiceProperties serviceProperties, Class<T> messageType, MessageHandler<T> handler) { TypeDictionary typeDictionary = new TypeDictionary(); ReflectionTypeDictionaryFactory reflectionCruft = new ReflectionTypeDictionaryFactory(null); typeDictionary.putAllParsers(reflectionCruft.populateParsersFromClasspath()); typeDictionary.putHandler(MessageType.of(messageType), handler); ConsumerFactory consumerFactory = new ConsumerFactory(serviceProperties, typeDictionary, null, null); return consumerFactory; } }
ConsumerFactory consumerFactory = new ConsumerFactory(serviceProperties, typeDictionary, null, null); Consumer requestConsumer = consumerFactory.consumerForTopic(ping, new DiscardFailedMessages()); Consumer replyConsumer = consumerFactory.consumerForTopic(pong, new DiscardFailedMessages());