use of com.tangosol.net.topic.Subscriber in project coherence-spring by coherence-community.
the class NamedTopicConfigurationTest method shouldInjectPublisher.
@Test
public void shouldInjectPublisher() throws Exception {
NamedTopicPublisherFieldsBean publisherBean = this.ctx.getBean(NamedTopicPublisherFieldsBean.class);
NamedTopicSubscriberFieldsBean subscriberBean = this.ctx.getBean(NamedTopicSubscriberFieldsBean.class);
Publisher<Integer> numbersPublisher = publisherBean.getIntegers();
assertThat(numbersPublisher, is(notNullValue()));
Publisher<Person> peoplePublisher = publisherBean.getPeople();
assertThat(peoplePublisher, is(notNullValue()));
Subscriber<Integer> numbersSubscriber = subscriberBean.getIntegers();
assertThat(numbersSubscriber, is(notNullValue()));
Subscriber<Person> peopleSubscriber = subscriberBean.getPeople();
assertThat(peopleSubscriber, is(notNullValue()));
Subscriber<String> peopleFirstNamesSubscriber = subscriberBean.getPeopleFirstNames();
assertThat(peopleFirstNamesSubscriber, is(notNullValue()));
Subscriber<Person> peopleFilteredSubscriber = subscriberBean.getPeopleFiltered();
assertThat(peopleFilteredSubscriber, is(notNullValue()));
CompletableFuture<Subscriber.Element<Integer>> receiveNumber = numbersSubscriber.receive();
numbersPublisher.publish(19).join();
Subscriber.Element<Integer> element = receiveNumber.get(1, TimeUnit.MINUTES);
assertThat(element.getValue(), is(19));
Person homer = new Person("Homer", "Simpson", LocalDate.now(), new PhoneNumber(1, "555-123-9999"));
Person bart = new Person("Bart", "Simpson", LocalDate.now(), new PhoneNumber(1, "555-123-9999"));
CompletableFuture<Subscriber.Element<Person>> receivePerson = peopleSubscriber.receive();
CompletableFuture<Subscriber.Element<String>> receiveName = peopleFirstNamesSubscriber.receive();
CompletableFuture<Subscriber.Element<Person>> receiveFiltered = peopleFilteredSubscriber.receive();
peoplePublisher.publish(homer).join();
Subscriber.Element<Person> personElement = receivePerson.get(1, TimeUnit.MINUTES);
Subscriber.Element<String> nameElement = receiveName.get(1, TimeUnit.MINUTES);
assertThat(personElement.getValue(), is(homer));
assertThat(nameElement.getValue(), is(homer.getFirstName()));
assertThat(receiveFiltered.isDone(), is(false));
peoplePublisher.publish(bart).join();
personElement = receiveFiltered.get(1, TimeUnit.MINUTES);
assertThat(personElement.getValue(), is(bart));
}
use of com.tangosol.net.topic.Subscriber in project micronaut-coherence by micronaut-projects.
the class CoherenceSubscriberExceptionTest method testFourArgCauseCtor.
@Test
void testFourArgCauseCtor() {
Subscriber<?> subscriber = mock(Subscriber.class);
Subscriber.Element<?> element = mock(Subscriber.Element.class);
Throwable cause = new RuntimeException();
CoherenceSubscriberException exception = new CoherenceSubscriberException(cause, Integer.MAX_VALUE, subscriber, element);
assertThat(exception.getMessage(), nullValue());
assertThat(exception.getCause(), is(cause));
assertThat(exception.getKafkaListener(), is(Integer.MAX_VALUE));
assertThat(exception.getKafkaConsumer(), is(subscriber));
Optional<Subscriber.Element<?>> optElement = exception.getElement();
assertThat(optElement, notNullValue());
assertThat(optElement.orElseThrow(AssertionFailedError::new), is(element));
}
use of com.tangosol.net.topic.Subscriber in project coherence-spring by coherence-community.
the class NamedTopicConfiguration method getSubscriber.
@SuppressWarnings("unchecked")
@Bean(destroyMethod = "release")
@DependsOn(CoherenceSpringConfiguration.COHERENCE_SERVER_BEAN_NAME)
@Primary
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
<V> Subscriber<V> getSubscriber(InjectionPoint injectionPoint) {
List<Subscriber.Option> options = new ArrayList<>();
final MergedAnnotations mergedAnnotations = MergedAnnotations.from(injectionPoint.getAnnotatedElement());
final MergedAnnotation<SubscriberGroup> mergedSubscribedGroupAnnotation = mergedAnnotations.get(SubscriberGroup.class);
if (mergedSubscribedGroupAnnotation.isPresent()) {
String subscribedGroupName = mergedSubscribedGroupAnnotation.synthesize().value();
if (StringUtils.hasLength(subscribedGroupName)) {
options.add(Subscriber.Name.of(subscribedGroupName));
}
}
final MergedAnnotation<FilterBinding> mergedFilterBindingAnnotation = mergedAnnotations.get(FilterBinding.class);
if (mergedFilterBindingAnnotation.isPresent()) {
Filter filter = this.filterService.getFilter(injectionPoint);
options.add(Subscriber.Filtered.by(filter));
}
final MergedAnnotation<ExtractorBinding> mergedExtractorBindingAnnotation = mergedAnnotations.get(ExtractorBinding.class);
if (mergedExtractorBindingAnnotation.isPresent()) {
ValueExtractor extractor = this.extractorService.getExtractor(injectionPoint);
options.add(Subscriber.Convert.using(extractor));
}
NamedTopic<V> topic = getTopicInternal(injectionPoint);
return options.isEmpty() ? topic.createSubscriber() : topic.createSubscriber(options.toArray(new Subscriber.Option[0]));
}
use of com.tangosol.net.topic.Subscriber in project micronaut-coherence by micronaut-projects.
the class NamedTopicFactories method getSubscriber.
@Bean(preDestroy = "close")
@Prototype
@Type(Subscriber.class)
@SuppressWarnings({ "unchecked", "rawtypes" })
<V> Subscriber<V> getSubscriber(InjectionPoint<?> injectionPoint) {
AnnotationMetadata metadata = injectionPoint.getAnnotationMetadata();
List<Subscriber.Option> options = new ArrayList<>();
String groupName = metadata.getValue(SubscriberGroup.class, String.class).orElse(null);
if (StringUtils.isNotEmpty(groupName)) {
options.add(Subscriber.Name.of(groupName));
}
if (metadata.hasStereotype(FilterBinding.class)) {
Filter filter = filterFactory.filter(injectionPoint);
options.add(Subscriber.Filtered.by(filter));
}
if (metadata.hasStereotype(ExtractorBinding.class)) {
ValueExtractor extractor = extractorFactory.extractor(injectionPoint);
options.add(Subscriber.Convert.using(extractor));
}
NamedTopic<V> topic = getTopicInternal(injectionPoint);
return options.isEmpty() ? topic.createSubscriber() : topic.createSubscriber(options.toArray(new Subscriber.Option[0]));
}
use of com.tangosol.net.topic.Subscriber in project micronaut-coherence by micronaut-projects.
the class NamedTopicFactoriesTest method shouldInjectPublisher.
@Test
public void shouldInjectPublisher() throws Exception {
NamedTopicPublisherFieldsBean publisherBean = ctx.getBean(NamedTopicPublisherFieldsBean.class);
NamedTopicSubscriberFieldsBean subscriberBean = ctx.getBean(NamedTopicSubscriberFieldsBean.class);
Publisher<Integer> numbersPublisher = publisherBean.getNumbers();
assertThat(numbersPublisher, is(notNullValue()));
Publisher<Person> peoplePublisher = publisherBean.getPeople();
assertThat(peoplePublisher, is(notNullValue()));
Subscriber<Integer> numbersSubscriber = subscriberBean.getNumbers();
assertThat(numbersSubscriber, is(notNullValue()));
Subscriber<Person> peopleSubscriber = subscriberBean.getPeople();
assertThat(peopleSubscriber, is(notNullValue()));
Subscriber<String> peopleFirstNamesSubscriber = subscriberBean.getPeopleFirstNames();
assertThat(peopleFirstNamesSubscriber, is(notNullValue()));
Subscriber<Person> peopleFilteredSubscriber = subscriberBean.getPeopleFiltered();
assertThat(peopleFilteredSubscriber, is(notNullValue()));
CompletableFuture<Subscriber.Element<Integer>> receiveNumber = numbersSubscriber.receive();
numbersPublisher.send(19).join();
Subscriber.Element<Integer> element = receiveNumber.get(1, TimeUnit.MINUTES);
assertThat(element.getValue(), is(19));
Person homer = new Person("Homer", "Simpson", LocalDate.now(), new PhoneNumber(1, "555-123-9999"));
Person bart = new Person("Bart", "Simpson", LocalDate.now(), new PhoneNumber(1, "555-123-9999"));
CompletableFuture<Subscriber.Element<Person>> receivePerson = peopleSubscriber.receive();
CompletableFuture<Subscriber.Element<String>> receiveName = peopleFirstNamesSubscriber.receive();
CompletableFuture<Subscriber.Element<Person>> receiveFiltered = peopleFilteredSubscriber.receive();
peoplePublisher.send(homer).join();
Subscriber.Element<Person> personElement = receivePerson.get(1, TimeUnit.MINUTES);
Subscriber.Element<String> nameElement = receiveName.get(1, TimeUnit.MINUTES);
assertThat(personElement.getValue(), is(homer));
assertThat(nameElement.getValue(), is(homer.getFirstName()));
assertThat(receiveFiltered.isDone(), is(false));
peoplePublisher.send(bart).join();
personElement = receiveFiltered.get(1, TimeUnit.MINUTES);
assertThat(personElement.getValue(), is(bart));
}
Aggregations