Pil0tXia commented on code in PR #3862: URL: https://github.com/apache/eventmesh/pull/3862#discussion_r1575645832
########## eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/producer/OpenMessageGrpProducer.java: ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.client.grpc.producer; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.util.EventMeshClientUtil; +import org.apache.eventmesh.common.enums.EventMeshProtocolType; +import org.apache.eventmesh.common.protocol.grpc.protos.BatchMessage; +import org.apache.eventmesh.common.protocol.grpc.protos.PublisherServiceGrpc.PublisherServiceBlockingStub; +import org.apache.eventmesh.common.protocol.grpc.protos.Response; +import org.apache.eventmesh.common.protocol.grpc.protos.SimpleMessage; + +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; +import java.util.concurrent.TimeUnit; + + +import io.openmessaging.api.Message; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class OpenMessageGrpProducer implements GrpcProducer<Message> { + + private static final EventMeshProtocolType PROTOCOL_TYPE = EventMeshProtocolType.OPEN_MESSAGE; + + private final EventMeshGrpcClientConfig clientConfig; + + private final PublisherServiceBlockingStub publisherClient; + + public OpenMessageGrpProducer(EventMeshGrpcClientConfig clientConfig, PublisherServiceBlockingStub publisherClient) { + this.clientConfig = clientConfig; + this.publisherClient = publisherClient; + } + + @Override + public Response publish(Message message) { + + if (null == message) { + return null; + } + + if (log.isDebugEnabled()) { + log.info("Publish message: {}", message); + } + SimpleMessage simpleMessage = EventMeshClientUtil.buildSimpleMessage(message, clientConfig, PROTOCOL_TYPE); + try { + Response response = publisherClient.publish(simpleMessage); + if (log.isInfoEnabled()) { + log.info("Received response:{}", response); + } + return response; + } catch (Exception e) { + log.error("Error in publishing message {}", message, e); + } + return null; + } + + @Override + public Response publish(List<Message> messages) { + + if (CollectionUtils.isEmpty(messages)) { + return null; + } + BatchMessage batchMessage = EventMeshClientUtil.buildBatchMessages(messages, clientConfig, PROTOCOL_TYPE); + try { + Response response = publisherClient.batchPublish(batchMessage); + if (log.isInfoEnabled()) { + log.info("Received response:{}", response); + } + return response; + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Error in BatchPublish message {}", messages, e); + } + } + return null; + } + + @Override + public Message requestReply(final Message message, long timeout) { + if (log.isInfoEnabled()) { + log.info("RequestReply message:{}", message); + } + + SimpleMessage simpleMessage = EventMeshClientUtil.buildSimpleMessage(message, clientConfig, PROTOCOL_TYPE); Review Comment: SimpleMessage has been renamed. Please resolve conflicts~ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@eventmesh.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@eventmesh.apache.org For additional commands, e-mail: issues-h...@eventmesh.apache.org