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 interfaceThe Publisher type which is returned bygetPublisher().static interfaceRepresents a subscription. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcheckValidName(String name) Checks if the suppliedTopicname 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.SubscriptionsubscribeNext(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 eitherConsumerwill 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.Subscriptioninstance. 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 suppliedTopicname is valid.- Parameters:
name- the name to check- Returns:
- the value passed to the function
- Throws:
IllegalArgumentException- if the name is not valid
-