use of org.springframework.cloud.stream.binding.Bindable in project spring-cloud-stream by spring-cloud.
the class BinderAwareChannelResolverTests method resolveChannel.
@Test
public void resolveChannel() {
Map<String, Bindable> bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(0, bindable.getOutputs().size());
}
MessageChannel registered = resolver.resolveDestination("foo");
assertEquals(2, ((AbstractMessageChannel) registered).getChannelInterceptors().size());
assertTrue(((AbstractMessageChannel) registered).getChannelInterceptors().get(1) instanceof ImmutableMessageChannelInterceptor);
bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(1, bindable.getOutputs().size());
}
DirectChannel testChannel = new DirectChannel();
testChannel.setComponentName("INPUT");
final CountDownLatch latch = new CountDownLatch(1);
final List<Message<?>> received = new ArrayList<>();
testChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
received.add(message);
latch.countDown();
}
});
this.binder.bindConsumer("foo", null, testChannel, new ConsumerProperties());
assertThat(received).hasSize(0);
registered.send(MessageBuilder.withPayload("hello").build());
try {
assertThat(latch.await(1, TimeUnit.SECONDS)).describedAs("Latch timed out");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("interrupted while awaiting latch");
}
assertThat(received).hasSize(1);
assertThat(new String((byte[]) received.get(0).getPayload())).isEqualTo("hello");
this.context.close();
for (Bindable bindable : bindables.values()) {
assertEquals(0, bindable.getInputs().size());
// Must not be bound"
assertEquals(0, bindable.getOutputs().size());
}
}
use of org.springframework.cloud.stream.binding.Bindable in project spring-cloud-stream by spring-cloud.
the class ExtendedPropertiesBinderAwareChannelResolverTests method resolveChannel.
@Test
@Override
public void resolveChannel() {
Map<String, Bindable> bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(0, bindable.getOutputs().size());
}
MessageChannel registered = resolver.resolveDestination("foo");
bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(1, bindable.getOutputs().size());
}
DirectChannel testChannel = new DirectChannel();
final CountDownLatch latch = new CountDownLatch(1);
final List<Message<?>> received = new ArrayList<>();
testChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
received.add(message);
latch.countDown();
}
});
binder.bindConsumer("foo", null, testChannel, new ExtendedConsumerProperties<ConsumerProperties>(new ConsumerProperties()));
assertThat(received).hasSize(0);
registered.send(MessageBuilder.withPayload("hello").build());
try {
assertThat(latch.await(1, TimeUnit.SECONDS)).describedAs("latch timed out");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("interrupted while awaiting latch");
}
assertThat(received).hasSize(1);
assertThat(new String((byte[]) received.get(0).getPayload())).isEqualTo("hello");
context.close();
for (Bindable bindable : bindables.values()) {
assertEquals(0, bindable.getInputs().size());
// Must not be bound"
assertEquals(0, bindable.getOutputs().size());
}
}
use of org.springframework.cloud.stream.binding.Bindable in project spring-cloud-stream by spring-cloud.
the class ChannelsEndpoint method channels.
@ReadOperation
public Map<String, Object> channels() {
ChannelsMetaData map = new ChannelsMetaData();
Map<String, BindingProperties> inputs = map.getInputs();
Map<String, BindingProperties> outputs = map.getOutputs();
for (Bindable factory : this.adapters) {
for (String name : factory.getInputs()) {
inputs.put(name, this.properties.getBindingProperties(name));
}
for (String name : factory.getOutputs()) {
outputs.put(name, this.properties.getBindingProperties(name));
}
}
return new ObjectMapper().convertValue(map, new TypeReference<Map<String, Object>>() {
});
}
Aggregations