use of org.apache.eventmesh.common.protocol.SubscriptionItem in project incubator-eventmesh by apache.
the class CloudEventsAsyncSubscribe method main.
public static void main(String[] args) throws InterruptedException {
Properties properties = Utils.readPropertiesFile(ExampleConstants.CONFIG_FILE_NAME);
final String eventMeshIp = properties.getProperty(ExampleConstants.EVENTMESH_IP);
final String eventMeshGrpcPort = properties.getProperty(ExampleConstants.EVENTMESH_GRPC_PORT);
EventMeshGrpcClientConfig eventMeshClientConfig = EventMeshGrpcClientConfig.builder().serverAddr(eventMeshIp).serverPort(Integer.parseInt(eventMeshGrpcPort)).consumerGroup(ExampleConstants.DEFAULT_EVENTMESH_TEST_CONSUMER_GROUP).env("env").idc("idc").sys("1234").build();
org.apache.eventmesh.common.protocol.SubscriptionItem subscriptionItem = new SubscriptionItem();
subscriptionItem.setTopic(ExampleConstants.EVENTMESH_GRPC_ASYNC_TEST_TOPIC);
subscriptionItem.setMode(SubscriptionMode.CLUSTERING);
subscriptionItem.setType(SubscriptionType.ASYNC);
EventMeshGrpcConsumer eventMeshGrpcConsumer = new EventMeshGrpcConsumer(eventMeshClientConfig);
eventMeshGrpcConsumer.init();
eventMeshGrpcConsumer.registerListener(handler);
eventMeshGrpcConsumer.subscribe(Collections.singletonList(subscriptionItem));
Thread.sleep(60000);
eventMeshGrpcConsumer.unsubscribe(Collections.singletonList(subscriptionItem));
}
use of org.apache.eventmesh.common.protocol.SubscriptionItem in project incubator-eventmesh by apache.
the class CloudEventsSubscribeReply method main.
public static void main(String[] args) throws InterruptedException {
Properties properties = Utils.readPropertiesFile(ExampleConstants.CONFIG_FILE_NAME);
final String eventMeshIp = properties.getProperty(ExampleConstants.EVENTMESH_IP);
final String eventMeshGrpcPort = properties.getProperty(ExampleConstants.EVENTMESH_GRPC_PORT);
EventMeshGrpcClientConfig eventMeshClientConfig = EventMeshGrpcClientConfig.builder().serverAddr(eventMeshIp).serverPort(Integer.parseInt(eventMeshGrpcPort)).consumerGroup(ExampleConstants.DEFAULT_EVENTMESH_TEST_CONSUMER_GROUP).env("env").idc("idc").sys("1234").build();
SubscriptionItem subscriptionItem = new SubscriptionItem();
subscriptionItem.setTopic(ExampleConstants.EVENTMESH_GRPC_RR_TEST_TOPIC);
subscriptionItem.setMode(SubscriptionMode.CLUSTERING);
subscriptionItem.setType(SubscriptionType.SYNC);
EventMeshGrpcConsumer eventMeshGrpcConsumer = new EventMeshGrpcConsumer(eventMeshClientConfig);
eventMeshGrpcConsumer.init();
eventMeshGrpcConsumer.registerListener(handler);
eventMeshGrpcConsumer.subscribe(Collections.singletonList(subscriptionItem));
Thread.sleep(60000);
eventMeshGrpcConsumer.unsubscribe(Collections.singletonList(subscriptionItem));
}
use of org.apache.eventmesh.common.protocol.SubscriptionItem in project incubator-eventmesh by apache.
the class EventmeshSubscribeBroadcast method main.
public static void main(String[] args) throws InterruptedException {
Properties properties = Utils.readPropertiesFile(ExampleConstants.CONFIG_FILE_NAME);
final String eventMeshIp = properties.getProperty(ExampleConstants.EVENTMESH_IP);
final String eventMeshGrpcPort = properties.getProperty(ExampleConstants.EVENTMESH_GRPC_PORT);
EventMeshGrpcClientConfig eventMeshClientConfig = EventMeshGrpcClientConfig.builder().serverAddr(eventMeshIp).serverPort(Integer.parseInt(eventMeshGrpcPort)).consumerGroup(ExampleConstants.DEFAULT_EVENTMESH_TEST_CONSUMER_GROUP).env("env").idc("idc").sys("1234").build();
SubscriptionItem subscriptionItem = new SubscriptionItem();
subscriptionItem.setTopic(ExampleConstants.EVENTMESH_GRPC_BROADCAT_TEST_TOPIC);
subscriptionItem.setMode(SubscriptionMode.BROADCASTING);
subscriptionItem.setType(SubscriptionType.ASYNC);
EventMeshGrpcConsumer eventMeshGrpcConsumer = new EventMeshGrpcConsumer(eventMeshClientConfig);
eventMeshGrpcConsumer.init();
eventMeshGrpcConsumer.registerListener(handler);
eventMeshGrpcConsumer.subscribe(Collections.singletonList(subscriptionItem));
Thread.sleep(60000);
eventMeshGrpcConsumer.unsubscribe(Collections.singletonList(subscriptionItem));
}
use of org.apache.eventmesh.common.protocol.SubscriptionItem in project incubator-eventmesh by apache.
the class ClientGroupWrapper method initClientGroupPersistentConsumer.
public synchronized void initClientGroupPersistentConsumer() throws Exception {
if (inited4Persistent.get()) {
return;
}
Properties keyValue = new Properties();
keyValue.put("isBroadcast", "false");
keyValue.put("consumerGroup", group);
keyValue.put("eventMeshIDC", eventMeshTCPConfiguration.eventMeshIDC);
keyValue.put("instanceName", EventMeshUtil.buildMeshTcpClientID(sysId, "SUB", eventMeshTCPConfiguration.eventMeshCluster));
persistentMsgConsumer.init(keyValue);
EventListener listener = (event, context) -> {
eventMeshTcpMonitor.getTcpSummaryMetrics().getMq2eventMeshMsgNum().incrementAndGet();
event = CloudEventBuilder.from(event).withExtension(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())).withExtension(EventMeshConstants.REQ_RECEIVE_EVENTMESH_IP, eventMeshTCPConfiguration.eventMeshServerIp).build();
String topic = event.getSubject();
EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext) context;
Session session = downstreamDispatchStrategy.select(group, topic, groupConsumerSessions);
String bizSeqNo = EventMeshUtil.getMessageBizSeq(event);
if (session == null) {
try {
Integer sendBackTimes = 0;
String sendBackFromEventMeshIp = "";
if (StringUtils.isNotBlank(Objects.requireNonNull(event.getExtension(EventMeshConstants.EVENTMESH_SEND_BACK_TIMES)).toString())) {
sendBackTimes = (Integer) event.getExtension(EventMeshConstants.EVENTMESH_SEND_BACK_TIMES);
}
if (StringUtils.isNotBlank(Objects.requireNonNull(event.getExtension(EventMeshConstants.EVENTMESH_SEND_BACK_IP)).toString())) {
sendBackFromEventMeshIp = (String) event.getExtension(EventMeshConstants.EVENTMESH_SEND_BACK_IP);
}
logger.error("found no session to downstream msg,groupName:{}, topic:{}, " + "bizSeqNo:{}, sendBackTimes:{}, sendBackFromEventMeshIp:{}", group, topic, bizSeqNo, sendBackTimes, sendBackFromEventMeshIp);
if (sendBackTimes >= eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSendBackMaxTimes) {
logger.error("sendBack to broker over max times:{}, groupName:{}, topic:{}, " + "bizSeqNo:{}", eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSendBackMaxTimes, group, topic, bizSeqNo);
} else {
sendBackTimes++;
event = CloudEventBuilder.from(event).withExtension(EventMeshConstants.EVENTMESH_SEND_BACK_TIMES, sendBackTimes.toString()).withExtension(EventMeshConstants.EVENTMESH_SEND_BACK_IP, eventMeshTCPConfiguration.eventMeshServerIp).build();
sendMsgBackToBroker(event, bizSeqNo);
}
} catch (Exception e) {
logger.warn("handle msg exception when no session found", e);
}
eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage);
return;
}
SubscriptionItem subscriptionItem = subscriptions.get(topic);
DownStreamMsgContext downStreamMsgContext = new DownStreamMsgContext(event, session, persistentMsgConsumer, eventMeshAsyncConsumeContext.getAbstractContext(), false, subscriptionItem);
// msg put in eventmesh,waiting client ack
session.getPusher().unAckMsg(downStreamMsgContext.seq, downStreamMsgContext);
session.downstreamMsg(downStreamMsgContext);
eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck);
};
persistentMsgConsumer.registerEventListener(listener);
inited4Persistent.compareAndSet(false, true);
logger.info("init persistentMsgConsumer success, group:{}", group);
}
use of org.apache.eventmesh.common.protocol.SubscriptionItem in project incubator-eventmesh by apache.
the class MessageUtils method generateSubscription.
public static Subscription generateSubscription() {
List<SubscriptionItem> subscriptionItems = new ArrayList<>();
subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC));
subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC2", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC));
subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC3", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC));
subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC4", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC));
Subscription subscription = new Subscription();
subscription.setTopicList(subscriptionItems);
return subscription;
}
Aggregations