use of org.apache.eventmesh.connector.standalone.broker.model.TopicMetadata in project incubator-eventmesh by apache.
the class StandaloneBroker method getMessage.
/**
* Get the message, if the queue is empty return null
*
* @param topicName
*/
public CloudEvent getMessage(String topicName) {
TopicMetadata topicMetadata = new TopicMetadata(topicName);
MessageEntity head = messageContainer.computeIfAbsent(topicMetadata, k -> new MessageQueue()).getHead();
if (head == null) {
return null;
}
return head.getMessage();
}
use of org.apache.eventmesh.connector.standalone.broker.model.TopicMetadata in project incubator-eventmesh by apache.
the class StandaloneBroker method createTopicIfAbsent.
/**
* if topic not exist, create a topic
*
* @param topicName topicName
* @return messageQueue and offset
*/
public Pair<MessageQueue, AtomicLong> createTopicIfAbsent(String topicName) {
TopicMetadata topicMetadata = new TopicMetadata(topicName);
MessageQueue messageQueue = messageContainer.computeIfAbsent(topicMetadata, k -> new MessageQueue());
AtomicLong offset = offsetMap.computeIfAbsent(topicMetadata, k -> new AtomicLong());
return Pair.of(messageQueue, offset);
}
use of org.apache.eventmesh.connector.standalone.broker.model.TopicMetadata in project incubator-eventmesh by apache.
the class StandaloneBroker method putMessage.
/**
* put message
*
* @param topicName topic name
* @param message message
* @throws InterruptedException
*/
public MessageEntity putMessage(String topicName, CloudEvent message) throws InterruptedException {
Pair<MessageQueue, AtomicLong> pair = createTopicIfAbsent(topicName);
AtomicLong topicOffset = pair.getRight();
MessageQueue messageQueue = pair.getLeft();
MessageEntity messageEntity = new MessageEntity(new TopicMetadata(topicName), message, topicOffset.getAndIncrement(), System.currentTimeMillis());
messageQueue.put(messageEntity);
return messageEntity;
}
use of org.apache.eventmesh.connector.standalone.broker.model.TopicMetadata in project incubator-eventmesh by apache.
the class StandaloneBroker method getMessage.
/**
* Get the message by offset
*
* @param topicName topic name
* @param offset offset
* @return CloudEvent
*/
public CloudEvent getMessage(String topicName, long offset) {
TopicMetadata topicMetadata = new TopicMetadata(topicName);
MessageEntity messageEntity = messageContainer.computeIfAbsent(topicMetadata, k -> new MessageQueue()).getByOffset(offset);
if (messageEntity == null) {
return null;
}
return messageEntity.getMessage();
}
Aggregations