Class InMemoryConnector
- All Implemented Interfaces:
InboundConnector,OutboundConnector,org.eclipse.microprofile.reactive.messaging.spi.ConnectorFactory
-
Field Summary
FieldsFields inherited from interface org.eclipse.microprofile.reactive.messaging.spi.ConnectorFactory
CHANNEL_NAME_ATTRIBUTE, CONNECTOR_ATTRIBUTE, CONNECTOR_PREFIX, INCOMING_PREFIX, OUTGOING_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Switch back the channel to their original connector.Flow.Publisher<? extends org.eclipse.microprofile.reactive.messaging.Message<?>>getPublisher(org.eclipse.microprofile.config.Config config) Flow.Subscriber<? extends org.eclipse.microprofile.reactive.messaging.Message<?>>getSubscriber(org.eclipse.microprofile.config.Config config) <T> InMemorySink<T>Retrieves anInMemorySinkassociated to the channel namedchannel.<T> InMemorySource<T>Retrieves anInMemorySourceassociated to the channel namedchannel.switchIncomingChannelsToInMemory(String... channels) Switch the given incoming channel to in-memory.switchOutgoingChannelsToInMemory(String... channels) Switch the given outgoing channel to in-memory.
-
Field Details
-
CONNECTOR
- See Also:
-
-
Constructor Details
-
InMemoryConnector
public InMemoryConnector()
-
-
Method Details
-
switchIncomingChannelsToInMemory
Switch the given incoming channel to in-memory. It replaces the previously used connector with the in-memory connector.This method is generally used before tests to avoid using an external broker for a specific channel. You can then retrieve the
InMemorySourceusing:@Inject @Any InMemoryConnector connector; //... @Before public void setup() { InMemoryConnector.switchIncomingChannelsToInMemory("my-channel"); } // .. InMemorySource<Integer> channel = connector.source("my-channel"); channel.send(1); channel.send(2);- Parameters:
channels- the channels to switch, must not benull, must not containnull, must not contain a blank value- Returns:
- The map of properties that have been defined. The method sets the system properties, but give you this map to pass the properties around if needed.
-
switchOutgoingChannelsToInMemory
Switch the given outgoing channel to in-memory. It replaces the previously used connector with the in-memory connector.This method is generally used before tests to avoid using an external broker for a specific channel. You can then retrieve the
InMemorySinkusing:@Inject @Any InMemoryConnector connector; //... @Before public void setup() { InMemoryConnector.switchOutgoingChannelsToInMemory("my-channel"); } // .. InMemorySink<Integer> channel = connector.sink("my-channel"); assertThat(channel.received()).hasSize(3).extracting(Message::getPayload).containsExactly(1, 2);- Parameters:
channels- the channels to switch, must not benull, must not containnull, must not contain a blank value- Returns:
- The map of properties that have been defined. The method sets the system properties, but give you this map to pass these properties around if needed.
-
clear
public static void clear()Switch back the channel to their original connector.This method is generally used after tests to reset the original configuration.
-
getPublisher
public Flow.Publisher<? extends org.eclipse.microprofile.reactive.messaging.Message<?>> getPublisher(org.eclipse.microprofile.config.Config config) - Specified by:
getPublisherin interfaceInboundConnector
-
getSubscriber
public Flow.Subscriber<? extends org.eclipse.microprofile.reactive.messaging.Message<?>> getSubscriber(org.eclipse.microprofile.config.Config config) - Specified by:
getSubscriberin interfaceOutboundConnector
-
source
Retrieves anInMemorySourceassociated to the channel namedchannel. This channel must use the in-memory connected.The returned
InMemorySourcelets you send messages or payloads to the channel, mocking the real interactions.- Type Parameters:
T- the type of message or payload sent to the channel- Parameters:
channel- the name of the channel, must not benull- Returns:
- the source
- Throws:
IllegalArgumentException- if the channel name isnullor if the channel is not associated with the in-memory connector.- See Also:
-
sink
Retrieves anInMemorySinkassociated to the channel namedchannel. This channel must use the in-memory connected.The returned
InMemorySinklets you checks the messages sent to the channel.- Type Parameters:
T- the type of payload received by the channel- Parameters:
channel- the name of the channel, must not benull- Returns:
- the sink
- Throws:
IllegalArgumentException- if the channel name isnullor if the channel is not associated with the in-memory connector.- See Also:
-