@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); } }
public Consumer consumerForTopic(Topic topic, DiscardFailedMessages failedMessageStrategy) { String consumerGroupId = defaultConsumerGroupId(topic); return new Consumer(topic, consumerGroupId, defaultKafkaConfig(), defaultPartitionProcessorFactory(failedMessageStrategy)); }
@Override public void bootstrapComplete() throws InterruptedException { // Start a messaging consumer for the default inbox. ConsumerFactory consumerFactory = injector.getInstance(ConsumerFactory.class); consumerFactory.defaultInboxConsumer(new DiscardFailedMessages()); injector.getInstance(RandomEventHandler.class); super.bootstrapComplete(); } }
ConsumerFactory consumerFactory = new ConsumerFactory(serviceProperties, typeDictionary, null, null); Consumer requestConsumer = consumerFactory.consumerForTopic(ping, new DiscardFailedMessages()); Consumer replyConsumer = consumerFactory.consumerForTopic(pong, new DiscardFailedMessages());
).consumerForTopic(ping, new DiscardFailedMessages()); ).consumerForTopic(ping, new DiscardFailedMessages()); ).consumerForTopic(ping, new DiscardFailedMessages()); firstMessageProcessedConsumer3.await(); Thread.sleep(5000);
).consumerForTopic(cruft, new DiscardFailedMessages());
public Consumer defaultInboxConsumer(FailedMessageProcessor failedMessageStrategy) { String serviceName = serviceProperties.getServiceName(); Topic defaultInbox = Topic.defaultServiceInbox(serviceName); String consumerGroupId = defaultConsumerGroupId(defaultInbox); return new Consumer(defaultInbox, consumerGroupId, defaultKafkaConfig(), defaultPartitionProcessorFactory(failedMessageStrategy)); }
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; } }