Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Eventmeshmessage plugin #599

Merged
merged 40 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fb84d90
[Feature #564] Support CloudEvents protocols for pub/sub in EventMesh…
xwm1992 Oct 28, 2021
4e55912
support cloudevents api in eventmesh-connector-api module
xwm1992 Nov 1, 2021
e602004
Merge branch 'develop' of https://github.com/apache/incubator-eventme…
xwm1992 Nov 1, 2021
9adb5e9
Merge branch 'develop' of https://github.com/apache/incubator-eventme…
xwm1992 Nov 1, 2021
670c2f2
fix checkStyle
xwm1992 Nov 1, 2021
691bcb3
fix checkStyle
xwm1992 Nov 1, 2021
b6a4613
fix checkStyle
xwm1992 Nov 1, 2021
0ac6d4f
1.support LifeCycle.java
xwm1992 Nov 1, 2021
2239a65
fix remove the extra blank line
xwm1992 Nov 1, 2021
086f4e6
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 2, 2021
308dfd7
support cloudEvents
xwm1992 Nov 2, 2021
f288ae2
Add files via upload
qqeasonchen Nov 3, 2021
09b9a22
Update README.md
qqeasonchen Nov 3, 2021
f0f3108
support cloudEvents
xwm1992 Nov 8, 2021
0290837
support cloudEvents
xwm1992 Nov 9, 2021
90a28cc
[ISSUE #580] Add checkstyle gradle plugin (#581)
ruanwenjun Nov 10, 2021
4425aaf
support cloudEvents
xwm1992 Nov 10, 2021
0dce0ca
support cloudevents
xwm1992 Nov 10, 2021
9251e07
update wechat-official qr code
xwm1992 Nov 11, 2021
ff1c247
update mesh-helper qr code
xwm1992 Nov 11, 2021
00994c3
Add files via upload
qqeasonchen Nov 11, 2021
bcf0337
update README.md
xwm1992 Nov 11, 2021
4938cd7
update README.md
xwm1992 Nov 11, 2021
61d0410
Update .asf.yaml
qqeasonchen Nov 11, 2021
3166325
support cloudEvents
xwm1992 Nov 11, 2021
bbd3535
support cloudEvents
xwm1992 Nov 12, 2021
de99c54
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 12, 2021
ceaf33b
[ISSUE #588] Fix typo in README.md (#589)
nichozhan Nov 15, 2021
468386c
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 16, 2021
d2d2b7d
support cloudEvents
xwm1992 Nov 16, 2021
46f973d
[Bug #590] Consumer subscription topic is invalid (#590) (#592)
hagsyn Nov 16, 2021
cf8433a
support cloudEvents adaptor
xwm1992 Nov 16, 2021
18310a1
[Feature #562] Implement CloudEvents adaptor
xwm1992 Nov 17, 2021
3149552
Merge branch 'develop' of https://github.com/apache/incubator-eventme…
xwm1992 Nov 17, 2021
d7ddac8
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 17, 2021
c534985
[Feature #562] Implement EventMeshMessage protocol adaptor
xwm1992 Nov 18, 2021
024e462
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 18, 2021
f096294
supplement apache header
xwm1992 Nov 18, 2021
46d8a51
Merge branch 'cloudevents' of https://github.com/apache/incubator-eve…
xwm1992 Nov 19, 2021
0f34e98
1.update package name
xwm1992 Nov 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support cloudEvents
  • Loading branch information
xwm1992 committed Nov 12, 2021
commit bbd3535bc3bd669a367a7339d5fca5f9b6657063
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
/*
* 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.rocketmq.consumer;

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Properties;

import io.openmessaging.api.*;

import org.apache.eventmesh.api.EventMeshAction;
import org.apache.eventmesh.api.EventMeshAsyncConsumeContext;
import org.apache.eventmesh.connector.rocketmq.consumer.PushConsumerImpl;
import org.apache.eventmesh.connector.rocketmq.domain.NonStandardKeys;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class PushConsumerImplTest {
private Consumer consumer;

@Mock
private DefaultMQPushConsumer rocketmqPushConsumer;

@Before
public void before() throws Exception {
Properties consumerProp = new Properties();
consumerProp.setProperty(OMSBuiltinKeys.DRIVER_IMPL, "org.apache.eventmesh.connector.rocketmq.MessagingAccessPointImpl");
consumerProp.setProperty("access_points", "IP1:9876,IP2:9876");
final MessagingAccessPoint messagingAccessPoint = OMS.builder().build(consumerProp);//.endpoint("oms:rocketmq://IP1:9876,IP2:9876/namespace").build(config);

consumerProp.setProperty("message.model", "CLUSTERING");

//Properties consumerProp = new Properties();
consumerProp.put("CONSUMER_ID", "TestGroup");
consumer = messagingAccessPoint.createConsumer(consumerProp);


Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
field.setAccessible(true);
DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
field.set(consumer, rocketmqPushConsumer); //Replace

Mockito.when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
consumer.start();
}

@After
public void after() throws Exception {
Mockito.verify(rocketmqPushConsumer).getMessageListener();
consumer.shutdown();
}

@Test
public void testConsumeMessage() {
final byte[] testBody = new byte[]{'a', 'b'};

MessageExt consumedMsg = new MessageExt();
consumedMsg.setMsgId("NewMsgId");
consumedMsg.setBody(testBody);
consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
consumedMsg.setTopic("HELLO_QUEUE");
consumer.subscribe("HELLO_QUEUE", "*", new AsyncMessageListener() {
@Override
public void consume(Message message, AsyncConsumeContext context) {
assertThat(message.getSystemProperties("MESSAGE_ID")).isEqualTo("NewMsgId");
assertThat(message.getBody()).isEqualTo(testBody);
((EventMeshAsyncConsumeContext)context).commit(EventMeshAction.CommitMessage);
}
});
((MessageListenerConcurrently) rocketmqPushConsumer
.getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null);


}
}
///*
// * 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.rocketmq.consumer;
//
//import static org.assertj.core.api.Assertions.assertThat;
//
//import java.lang.reflect.Field;
//import java.util.Collections;
//import java.util.Properties;
//
//import io.openmessaging.api.*;
//
//import org.apache.eventmesh.api.EventMeshAction;
//import org.apache.eventmesh.api.EventMeshAsyncConsumeContext;
//import org.apache.eventmesh.connector.rocketmq.consumer.PushConsumerImpl;
//import org.apache.eventmesh.connector.rocketmq.domain.NonStandardKeys;
//import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
//import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
//import org.apache.rocketmq.common.message.MessageExt;
//import org.junit.After;
//import org.junit.Before;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.mockito.Mock;
//import org.mockito.Mockito;
//import org.mockito.junit.MockitoJUnitRunner;
//
//@RunWith(MockitoJUnitRunner.class)
//public class PushConsumerImplTest {
// private Consumer consumer;
//
// @Mock
// private DefaultMQPushConsumer rocketmqPushConsumer;
//
// @Before
// public void before() throws Exception {
// Properties consumerProp = new Properties();
// consumerProp.setProperty(OMSBuiltinKeys.DRIVER_IMPL, "org.apache.eventmesh.connector.rocketmq.MessagingAccessPointImpl");
// consumerProp.setProperty("access_points", "IP1:9876,IP2:9876");
// final MessagingAccessPoint messagingAccessPoint = OMS.builder().build(consumerProp);//.endpoint("oms:rocketmq://IP1:9876,IP2:9876/namespace").build(config);
//
// consumerProp.setProperty("message.model", "CLUSTERING");
//
// //Properties consumerProp = new Properties();
// consumerProp.put("CONSUMER_ID", "TestGroup");
// consumer = messagingAccessPoint.createConsumer(consumerProp);
//
//
// Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
// field.setAccessible(true);
// DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
// field.set(consumer, rocketmqPushConsumer); //Replace
//
// Mockito.when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
// consumer.start();
// }
//
// @After
// public void after() throws Exception {
// Mockito.verify(rocketmqPushConsumer).getMessageListener();
// consumer.shutdown();
// }
//
// @Test
// public void testConsumeMessage() {
// final byte[] testBody = new byte[]{'a', 'b'};
//
// MessageExt consumedMsg = new MessageExt();
// consumedMsg.setMsgId("NewMsgId");
// consumedMsg.setBody(testBody);
// consumedMsg.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
// consumedMsg.setTopic("HELLO_QUEUE");
// consumer.subscribe("HELLO_QUEUE", "*", new AsyncMessageListener() {
// @Override
// public void consume(Message message, AsyncConsumeContext context) {
// assertThat(message.getSystemProperties("MESSAGE_ID")).isEqualTo("NewMsgId");
// assertThat(message.getBody()).isEqualTo(testBody);
// ((EventMeshAsyncConsumeContext)context).commit(EventMeshAction.CommitMessage);
// }
// });
// ((MessageListenerConcurrently) rocketmqPushConsumer
// .getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null);
//
//
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

package org.apache.eventmesh.connector.standalone.broker.task;

import io.openmessaging.api.AsyncMessageListener;
import io.openmessaging.api.Message;
import org.apache.eventmesh.api.EventListener;
import org.apache.eventmesh.api.EventMeshAction;
import org.apache.eventmesh.api.EventMeshAsyncConsumeContext;
import org.apache.eventmesh.connector.standalone.broker.StandaloneBroker;
Expand All @@ -33,7 +32,7 @@ public class SubScribeTask implements Runnable {

private String topicName;
private StandaloneBroker standaloneBroker;
private AsyncMessageListener listener;
private EventListener listener;
private volatile boolean isRunning;

private AtomicInteger offset;
Expand All @@ -42,7 +41,7 @@ public class SubScribeTask implements Runnable {

public SubScribeTask(String topicName,
StandaloneBroker standaloneBroker,
AsyncMessageListener listener) {
EventListener listener) {
this.topicName = topicName;
this.standaloneBroker = standaloneBroker;
this.listener = listener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import io.cloudevents.CloudEvent;
import io.cloudevents.core.v1.CloudEventV1;
import io.openmessaging.api.Message;
import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException;

import java.util.List;

/**
* OpenMessage protocol adaptor, used to transform protocol between
Expand All @@ -37,6 +40,11 @@ public CloudEventV1 toCloudEventV1(T message) {
return null;
}

@Override
public List<CloudEventV1> toBatchCloudEventV1(T protocol) throws ProtocolHandleException {
return null;
}

@Override
public Package fromCloudEventV1(CloudEventV1 cloudEvent) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,17 @@ public void consume(CloudEvent event, AsyncConsumeContext context) {
listener = new EventListener() {
@Override
public void consume(CloudEvent event, AsyncConsumeContext context) {
String topic = message.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION);
String bizSeqNo = message.getSystemProperties(Constants.PROPERTY_MESSAGE_SEARCH_KEYS);
String uniqueId = message.getUserProperties(Constants.RMB_UNIQ_ID);

message.getUserProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
event = new CloudEventBuilder(event)
.withExtension(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis()))
.build();

String topic = event.getSubject();
String bizSeqNo = event.getExtension(Constants.PROPERTY_MESSAGE_SEARCH_KEYS).toString();
String uniqueId = event.getExtension(Constants.RMB_UNIQ_ID).toString();

if (messageLogger.isDebugEnabled()) {
messageLogger.debug("message|mq2eventMesh|topic={}|msg={}", topic, message);
messageLogger.debug("message|mq2eventMesh|topic={}|msg={}", topic, event);
} else {
messageLogger.info("message|mq2eventMesh|topic={}|bizSeqNo={}|uniqueId={}", topic, bizSeqNo, uniqueId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ public EventMeshHTTPServer getEventMeshHTTPServer() {
}

public void finish() {
if (eventMeshConsumer != null && context != null && msg != null) {
if (eventMeshConsumer != null && context != null && event != null) {
if (messageLogger.isDebugEnabled()) {
// messageLogger.debug("messageAcked|topic={}|msgId={}|cluster={}|broker={}|queueId={}|queueOffset={}", topic,
// msg.getMsgId(), msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_CLUSTER),
// msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_BROKER),
// msg.getQueueId(), msg.getQueueOffset());
}
eventMeshConsumer.updateOffset(topic, subscriptionItem.getMode(), Arrays.asList(msg), context);
eventMeshConsumer.updateOffset(topic, subscriptionItem.getMode(), Arrays.asList(event), context);
}
}

Expand Down
Loading