use of org.apache.eventmesh.common.protocol.grpc.protos.Subscription in project incubator-eventmesh by apache.
the class SubscribeStreamProcessor method doAclCheck.
private void doAclCheck(Subscription subscription) throws AclException {
RequestHeader header = subscription.getHeader();
if (eventMeshGrpcServer.getEventMeshGrpcConfiguration().eventMeshServerSecurityEnable) {
String remoteAdd = header.getIp();
String user = header.getUsername();
String pass = header.getPassword();
String subsystem = header.getSys();
for (Subscription.SubscriptionItem item : subscription.getSubscriptionItemsList()) {
Acl.doAclCheckInHttpReceive(remoteAdd, user, pass, subsystem, item.getTopic(), RequestCode.SUBSCRIBE.getRequestCode());
}
}
}
use of org.apache.eventmesh.common.protocol.grpc.protos.Subscription in project incubator-eventmesh by apache.
the class EventMeshGrpcConsumer method subscribe.
public void subscribe(List<SubscriptionItem> subscriptionItems) {
logger.info("Create streaming subscription: " + subscriptionItems);
if (listener == null) {
logger.error("Error in subscriber, no Event Listener is registered.");
return;
}
addSubscription(subscriptionItems, SDK_STREAM_URL);
Subscription subscription = buildSubscription(subscriptionItems, null);
synchronized (this) {
if (subStreamHandler == null) {
subStreamHandler = new SubStreamHandler<>(consumerAsyncClient, clientConfig, listener);
subStreamHandler.start();
}
}
subStreamHandler.sendSubscription(subscription);
}
use of org.apache.eventmesh.common.protocol.grpc.protos.Subscription in project incubator-eventmesh by apache.
the class EventMeshGrpcConsumer method buildSubscription.
private Subscription buildSubscription(List<SubscriptionItem> subscriptionItems, String url) {
Subscription.Builder builder = Subscription.newBuilder().setHeader(EventMeshClientUtil.buildHeader(clientConfig, EventMeshCommon.EM_MESSAGE_PROTOCOL_NAME)).setConsumerGroup(clientConfig.getConsumerGroup());
if (StringUtils.isNotEmpty(url)) {
builder.setUrl(url);
}
for (SubscriptionItem subscriptionItem : subscriptionItems) {
Subscription.SubscriptionItem.SubscriptionMode mode;
if (SubscriptionMode.CLUSTERING.equals(subscriptionItem.getMode())) {
mode = Subscription.SubscriptionItem.SubscriptionMode.CLUSTERING;
} else if (SubscriptionMode.BROADCASTING.equals(subscriptionItem.getMode())) {
mode = Subscription.SubscriptionItem.SubscriptionMode.BROADCASTING;
} else {
mode = Subscription.SubscriptionItem.SubscriptionMode.UNRECOGNIZED;
}
Subscription.SubscriptionItem.SubscriptionType type;
if (SubscriptionType.ASYNC.equals(subscriptionItem.getType())) {
type = Subscription.SubscriptionItem.SubscriptionType.ASYNC;
} else if (SubscriptionType.SYNC.equals(subscriptionItem.getType())) {
type = Subscription.SubscriptionItem.SubscriptionType.SYNC;
} else {
type = Subscription.SubscriptionItem.SubscriptionType.UNRECOGNIZED;
}
Subscription.SubscriptionItem item = Subscription.SubscriptionItem.newBuilder().setTopic(subscriptionItem.getTopic()).setMode(mode).setType(type).build();
builder.addSubscriptionItems(item);
}
return builder.build();
}
use of org.apache.eventmesh.common.protocol.grpc.protos.Subscription in project incubator-eventmesh by apache.
the class EventMeshGrpcConsumer method unsubscribe.
public Response unsubscribe(List<SubscriptionItem> subscriptionItems, String url) {
logger.info("Removing subscription: " + subscriptionItems + ", url: " + url);
removeSubscription(subscriptionItems);
Subscription subscription = buildSubscription(subscriptionItems, url);
try {
Response response = consumerClient.unsubscribe(subscription);
logger.info("Received response " + response.toString());
return response;
} catch (Exception e) {
logger.error("Error in unsubscribe. error {}", e.getMessage());
return null;
}
}
use of org.apache.eventmesh.common.protocol.grpc.protos.Subscription in project incubator-eventmesh by apache.
the class SubStreamHandler method createReceiver.
private StreamObserver<SimpleMessage> createReceiver() {
return new StreamObserver<SimpleMessage>() {
@Override
public void onNext(SimpleMessage message) {
T msg = EventMeshClientUtil.buildMessage(message, listener.getProtocolType());
if (msg instanceof Map) {
logger.info("Received message from Server." + message);
} else {
logger.info("Received message from Server.|seq={}|uniqueId={}|", message.getSeqNum(), message.getUniqueId());
Subscription streamReply = null;
try {
Optional<T> reply = listener.handle(msg);
if (reply.isPresent()) {
streamReply = buildReplyMessage(message, reply.get());
}
} catch (Throwable t) {
logger.error("Error in handling reply message.|seq={}|uniqueId={}|", message.getSeqNum(), message.getUniqueId(), t);
}
if (streamReply != null) {
logger.info("Sending reply message to Server.|seq={}|uniqueId={}|", streamReply.getReply().getSeqNum(), streamReply.getReply().getUniqueId());
senderOnNext(streamReply);
}
}
}
@Override
public void onError(Throwable t) {
logger.error("Received Server side error: " + t.getMessage());
close();
}
@Override
public void onCompleted() {
logger.info("Finished receiving messages from server.");
close();
}
};
}
Aggregations