@ApplicationScoped public class InMemoryConnector extends Object implements IncomingConnectorFactory, OutgoingConnectorFactory
| Modifier and Type | Field and Description |
|---|---|
static String |
CONNECTOR |
CHANNEL_NAME_ATTRIBUTE, CONNECTOR_ATTRIBUTE, CONNECTOR_PREFIX, INCOMING_PREFIX, OUTGOING_PREFIX| Constructor and Description |
|---|
InMemoryConnector() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clear()
Switch back the channel to their original connector.
|
org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder<? extends Message<?>> |
getPublisherBuilder(org.eclipse.microprofile.config.Config config)
Creates a channel for the given configuration.
|
org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder<? extends Message<?>,Void> |
getSubscriberBuilder(org.eclipse.microprofile.config.Config config)
Creates a channel for the given configuration.
|
<T> InMemorySink<T> |
sink(String channel)
Retrieves an
InMemorySink associated to the channel named channel. |
<T> InMemorySource<T> |
source(String channel)
Retrieves an
InMemorySource associated to the channel named channel. |
static void |
switchChannelToInMemory(String... channels)
Switch the given channel to in-memory.
|
public static final String CONNECTOR
public static void switchChannelToInMemory(String... channels)
This method is generally used before tests to avoid using an external broker for a specific channel. You can then
retrieve the InMemorySource using:
@Inject @Any
InMemoryConnector connector;
//...
InMemorySource<Integer> channel = connector.source("my-channel");
channel.send(1);
channel.send(2);
With the InMemorySource, you can send messages to the channel, mocking the incoming messages.
You can also retrieve an InMemorySink using:
@Inject @Any
InMemoryConnector connector;
//...
InMemorySink<Integer> channel = connector.sink("my-channel");
assertThat(channel.received()).hasSize(3).extracting(Message::getPayload).containsExactly(1, 2);
With the InMemorySink, you can checked the messages received by the channel, to verify that the expected
messages have been received.
channels - the channels to switch, must not be null, must not contain null, must not contain
a blank valuepublic static void clear()
This method is generally used after tests to reset the original configuration.
public org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder<? extends Message<?>> getPublisherBuilder(org.eclipse.microprofile.config.Config config)
IncomingConnectorFactoryconnector, using the Connector qualifier's parameter indicating a key to
which IncomingConnectorFactory to use.
Note that the connection to the transport or broker is generally postponed until the subscription occurs.
getPublisherBuilder in interface IncomingConnectorFactoryconfig - the configuration, must not be null, must contain the ConnectorFactory.CHANNEL_NAME_ATTRIBUTE
attribute.PublisherBuilder, will not be null.public org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder<? extends Message<?>,Void> getSubscriberBuilder(org.eclipse.microprofile.config.Config config)
OutgoingConnectorFactoryconnector, using the Connector qualifier's parameter indicating a key to
which Outgoing to use.
Note that the connection to the transport or broker is generally postponed until the subscription.
getSubscriberBuilder in interface OutgoingConnectorFactoryconfig - the configuration, never null, must contain the ConnectorFactory.CHANNEL_NAME_ATTRIBUTE
attribute.SubscriberBuilder, must not be null.public <T> InMemorySource<T> source(String channel)
InMemorySource associated to the channel named channel.
This channel must use the in-memory connected.
The returned InMemorySource lets you send messages or payloads to the channel, mocking the real
interactions.
T - the type of message or payload sent to the channelchannel - the name of the channel, must not be nullIllegalArgumentException - if the channel name is null or if the channel is not associated with the
in-memory connector.switchChannelToInMemory(String...)public <T> InMemorySink<T> sink(String channel)
InMemorySink associated to the channel named channel.
This channel must use the in-memory connected.
The returned InMemorySink lets you checks the messages sent to the channel.
T - the type of payload received by the channelchannel - the name of the channel, must not be nullIllegalArgumentException - if the channel name is null or if the channel is not associated with the
in-memory connector.switchChannelToInMemory(String...)Copyright © 2018–2020 SmallRye. All rights reserved.