Interface Topic<T>
public interface Topic<T>
Represents a system-wide topic which can be used as a place to publish and subscribe to messages. The simple
operations.
Instances of
Topic
are considered to be lightweight and do not necessairly hold resources on their own, but
rather provide a means to open a connection to the underlying topic service. Both the subscribe(Consumer)
and getPublisher()
methods return types
Created by patricktwohig on 7/20/17.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
The Publisher type which is returned bygetPublisher()
.static interface
Represents a subscription. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String
checkValidName
(String name) Checks if the suppliedTopic
name is valid.Opens a connection to the underlying topic service and allows for the publication of messages on a particuilar topic.getSubtopicNamed
(String name) Returns a subtopic with the provided name.Listens for incoming messages on thisTopic
.default Topic.Subscription
subscribeNext
(Consumer<T> consumer, Consumer<Exception> exceptionConsumer) Similar tosubscribe(Consumer)
, this will subscribe to messages.
-
Field Details
-
VALID_NAME_PATTERN
-
-
Method Details
-
subscribe
Listens for incoming messages on thisTopic
. -
subscribeNext
default Topic.Subscription subscribeNext(Consumer<T> consumer, Consumer<Exception> exceptionConsumer) Similar tosubscribe(Consumer)
, this will subscribe to messages. However, this will automatically invokeTopic.Subscription.close()
once the first message has been processed. One of eitherConsumer
will be called, at most, once.- Parameters:
consumer
- theConsumer<T>
which will accept the next messageexceptionConsumer
- aConsumer<Exception>
instance which will handle possible exceptions invokingTopic.Subscription.close()
- Returns:
- a
Topic.Subscription
instance. InvokingTopic.Subscription.close()
a second time on this is guaranteed to have no ill-effects
-
getPublisher
Topic.Publisher<T> getPublisher()Opens a connection to the underlying topic service and allows for the publication of messages on a particuilar topic. -
getSubtopicNamed
Returns a subtopic with the provided name. The sub-topic's name will be appended to this topic's name. Events published to this topic will- Parameters:
name
-- Returns:
-
checkValidName
Checks if the suppliedTopic
name is valid.- Parameters:
name
- the name to check- Returns:
- the value passed to the function
- Throws:
IllegalArgumentException
- if the name is not valid
-