Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5d04127
commit emesher,sdk-java,common
HiddenWorld-lk Jul 27, 2025
db527e5
improve build script of emesher
wqliang Aug 7, 2020
196e492
add: add eventmesh-sdk-java-quickstart user guide
lrhkobe Aug 7, 2020
844827d
zh_CN doc fix
iNanos Aug 26, 2020
9bf7c0f
delete deploy pa
iNanos Aug 27, 2020
578fe17
Set theme jekyll-theme-cayman
qqeasonchen Oct 14, 2020
d97a978
Set theme jekyll-theme-cayman
qqeasonchen Oct 16, 2020
b30cc6b
event mesh project architecture adjustment
HiddenWorld-lk Jul 27, 2025
f037533
[ISSUE #219]Supply detail information or read.me for eventmesh runnin…
xwm1992 Mar 11, 2021
fd6d1fd
[ISSUE #219]Supply detail information or read.me for eventmesh runnin…
xwm1992 Mar 11, 2021
09e6b93
[ISSUE #265]rename wemq and access to eventmesh
HiddenWorld-lk Jul 27, 2025
adf7bd4
refactor(eventmesh-sdk-java):rename to org.apache(#281)
HiddenWorld-lk Jul 27, 2025
9a8a3e4
Refactor 'eventmesh-test' package name to org.apache #283
Apr 20, 2021
731f284
Refactor 'eventmesh-test' package name to org.apache #283
Apr 20, 2021
524372a
Refactor 'eventmesh-test' package name to org.apache #283
Apr 20, 2021
3386f70
Refactor 'eventmesh-test' package name to org.apache #283
Apr 20, 2021
cf8584f
update eventmesh-panels.png (#363)
xwm1992 May 22, 2021
6dfab4e
[ISSUE #366] remove custom concept [dcn&&region] (#390)
iNanos Jun 21, 2021
f4a5f29
[ISSUE #442] Fix findings filtered by Checkstyle workflow (#443)
HiddenWorld-lk Jul 27, 2025
5d207df
[ISSUE #442] Fix findings filtered by Checkstyle workflow (#443)
HiddenWorld-lk Jul 27, 2025
694c244
[ISSUE #442] Fix findings filtered by Checkstyle workflow (#443)
HiddenWorld-lk Jul 27, 2025
95dae60
Add EventMeshTCPClient, this client wrap the sub/sub client (#611)
ruanwenjun Nov 25, 2021
2c65601
add runtime unit tests
Jun 25, 2022
9f619a9
Update LICENSE
qqeasonchen Nov 15, 2019
4cff4e2
Update LICENSE
ivanzhongyq Nov 15, 2019
476b9d7
Update LICENSE
qqeasonchen Nov 15, 2019
dc5acd1
Add files via upload
qqeasonchen Nov 21, 2019
e804991
Add files via upload
qqeasonchen Jul 20, 2020
e8be10e
Revert "add init rocketmq home path"
qqeasonchen Jul 21, 2020
d0bfb0f
delete deploy pa
iNanos Aug 27, 2020
9d81c30
Set theme jekyll-theme-cayman
qqeasonchen Oct 14, 2020
912912b
Set theme jekyll-theme-cayman
qqeasonchen Oct 16, 2020
89d2201
update eventmesh-panels.png (#363)
xwm1992 May 22, 2021
62a78c5
Update LICENSE
qqeasonchen Nov 15, 2019
587f62b
Update LICENSE
ivanzhongyq Nov 15, 2019
caa7901
Update LICENSE
qqeasonchen Nov 15, 2019
297515f
Add files via upload
qqeasonchen Nov 21, 2019
b991071
Add files via upload
qqeasonchen Jul 20, 2020
e35d157
Revert "add init rocketmq home path"
qqeasonchen Jul 21, 2020
55592cc
delete deploy pa
iNanos Aug 27, 2020
7b360b6
Set theme jekyll-theme-cayman
qqeasonchen Oct 14, 2020
43efe5b
Set theme jekyll-theme-cayman
qqeasonchen Oct 16, 2020
2cee091
update eventmesh-panels.png (#363)
xwm1992 May 22, 2021
e985cff
add registry by zookeeper
Jun 17, 2022
e02d225
Zookeeper registry classes renamed.
Jun 20, 2022
f306fa5
1. Zookeeper registry build error fix; 2. Zookeeper registry test cas…
Jun 20, 2022
04fa21d
[ISSUE #3466]Save and re-use this "Random" (#3853)
harshithasudhakar May 10, 2023
0e8af85
[ISSUE #4001] Add eventmesh-sdks module (#4002)
HiddenWorld-lk Jul 27, 2025
6a490e2
[ISSUE #4478] Upgrade JUnit to JUnit Jupiter (#4475)
mureinik Oct 10, 2023
c28f0c1
add : eventmesh-retry/eventmesh-retry-kafka
HiddenWorld-lk Oct 3, 2024
409b9e4
update code style
Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
120 changes: 120 additions & 0 deletions docs/en/instructions/eventmesh-sdk-java-quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
## How to run eventmesh-sdk-java demo

> Eventmesh-sdk-java , as the client, communicated with eventmesh-runtime, used to complete the sending and receiving of message.
>
> Eventmesh-sdk-java supports sync msg, async msg and broadcast msg. Sync msg means the producer sends msg which need the consumer supplies the response msg, Async msg means the producer just sends msg and does not care reply msg.Broadcast msg means the producer send msg once and all the consumer subscribed the broadcast topic will receive the msg.
>
> Eventmesh-sdk-java supports the protocol of HTTP and TCP.



### 1. TCP DEMO

#### Sync msg

- create topic

```
sh runadmin.sh updateTopic -c ${ClusterName} -t ${topic} -n ${namesrvAddr}
```



* start consumer ,subscribe topic in previous step.

```
Run the main method of cn.webank.eventmesh.client.tcp.demo.SyncResponse
```



* start producer, send message

```
Run the main method of cn.webank.eventmesh.client.tcp.demo.SyncRequest
```



#### Async msg

- create topic

```
sh runadmin.sh updateTopic -c ${ClusterName} -t ${topic} -n ${namesrvAddr}
```



- start consumer ,subscribe topic in previous step.

```
Run the main method of cn.webank.eventmesh.client.tcp.demo.AsyncSubscribe
```



start producer, send message

```
Run the main method of cn.webank.eventmesh.client.tcp.demo.AsyncPublish
```



#### Broadcast msg

- create topic

```
sh runadmin.sh updateTopic -c ${ClusterName} -t ${topic} -n ${namesrvAddr}
```



- start consumer ,subscribe topic in previous step.

```
Run the main method of cn.webank.eventmesh.client.tcp.demo.AsyncSubscribeBroadcast
```



* start producer, send broadcast message

```
Run the main method of cn.webank.eventmesh.client.tcp.demo.AsyncPublishBroadcast
```

### 2. HTTP DEMO

> As to http, eventmesh-sdk-java just implements the sending of msg. And it already supports sync msg and async msg.
>
> In the demo ,the field of `content` of the java class `LiteMessage` represents a special protocal, so if you want to use http-client of eventmesh-sdk-java, you just need to design the content of protocal and supply the consumer appliacation at the same time.



#### Sync msg

> send msg ,producer need waiting until receive the response msg of consumer

```
Run the main method of cn.webank.eventmesh.client.http.demo.SyncRequestInstance
```



> send msg,producer handles the reponse msg in callback

```
Run the main method ofcn.webank.eventmesh.client.http.demo.AsyncSyncRequestInstance
```



#### Async msg

```
Run the main method of cn.webank.eventmesh.client.http.demo.AsyncPublishInstance
```

Binary file added docs/images/docker/docker-exec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/docker/docker-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/docker/docker-logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/docker/docker-ps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/eventmesh-test-structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 cn.webank.eventmesh.common;

public class Constants {

public static final String DEFAULT_CHARSET = "UTF-8";

public static final String TARGET_PROXY_REGION = "TARGET_PROXY_REGION";

public static final String CONSTANTS_DEFAULT_REGION_KEY = "default";

public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";

public static final String LANGUAGE_JAVA = "JAVA";

public static final String HTTP_PROTOCOL_PREFIX = "http://";

public static final int DEFAULT_HTTP_TIME_OUT = 3000;

public static final String PROXY_MESSAGE_CONST_TTL = "ttl";

public static final Integer DEFAULT_CLIENT_UNACK = 12;

public static final String CONSTANTS_SERVICE_DESC_ENV = "env";

public static final String CONSTANTS_SERVICE_DESC_VERSION = "version";

public static final String CONSTANTS_INSTANCE_DESC_ENV = "env";

public static final String CONSTANTS_INSTANCE_DESC_IDC = "idc";

public static final String CONSTANTS_INSTANCE_DESC_DCN = "dcn";

public static final String CONSTANTS_INSTANCE_DESC_SYSID = "sysId";

public static final String CONSTANTS_INSTANCE_DESC_IP = "ip";

public static final String CONSTANTS_INSTANCE_DESC_PORT = "port";

public static final String KEY_CONSTANTS_INSTANCE_DESC_PID = "pid";

public static final String RMB_UNIQ_ID = "RMB_UNIQ_ID";

public static final String IDC_SEPERATER = "-";

}
150 changes: 150 additions & 0 deletions eventmesh-common/src/main/java/cn/webank/eventmesh/common/IPUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* 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 cn.webank.eventmesh.common;

import io.netty.channel.Channel;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;

public class IPUtil {

public static String getLocalAddress() {
//获取docker宿主机ip
String dockerHostIp = System.getenv("webank_docker_host_ip");
if (dockerHostIp != null && !"".equals(dockerHostIp))
return dockerHostIp;
//priority of networkInterface when generating client ip
String priority = System.getProperty("networkInterface.priority", "eth0<eth1<bond1");
// LOGGER.info("networkInterface.priority: {}", priority);
ArrayList<String> preferList = new ArrayList<String>();
for (String eth : priority.split("<")) {
preferList.add(eth);
}
NetworkInterface preferNetworkInterface = null;

try {
Enumeration<NetworkInterface> enumeration1 = NetworkInterface.getNetworkInterfaces();
while (enumeration1.hasMoreElements()) {
final NetworkInterface networkInterface = enumeration1.nextElement();
// LOGGER.debug("networkInterface:{}", networkInterface);

if (!preferList.contains(networkInterface.getName())) {
continue;
} else if (preferNetworkInterface == null) {
preferNetworkInterface = networkInterface;
}
//get the networkInterface that has higher priority
else if (preferList.indexOf(networkInterface.getName())
> preferList.indexOf(preferNetworkInterface.getName())) {
preferNetworkInterface = networkInterface;
}
}

// Traversal Network interface to get the first non-loopback and non-private address
ArrayList<String> ipv4Result = new ArrayList<String>();
ArrayList<String> ipv6Result = new ArrayList<String>();

if (preferNetworkInterface != null) {
// LOGGER.info("use preferNetworkInterface:{}", preferNetworkInterface);
final Enumeration<InetAddress> en = preferNetworkInterface.getInetAddresses();
getIpResult(ipv4Result, ipv6Result, en);
} else {
// LOGGER.info("no preferNetworkInterface");
Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
while (enumeration.hasMoreElements()) {
final NetworkInterface networkInterface = enumeration.nextElement();
final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
getIpResult(ipv4Result, ipv6Result, en);
}
}

// prefer ipv4
if (!ipv4Result.isEmpty()) {
for (String ip : ipv4Result) {
if (ip.startsWith("127.0") || ip.startsWith("192.168")) {
continue;
}

return ip;
}

return ipv4Result.get(ipv4Result.size() - 1);
} else if (!ipv6Result.isEmpty()) {
return ipv6Result.get(0);
}
//If failed to find,fall back to localhost
final InetAddress localHost = InetAddress.getLocalHost();
return normalizeHostAddress(localHost);
} catch (SocketException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}

return null;
}

private static void getIpResult(ArrayList<String> ipv4Result, ArrayList<String> ipv6Result,
Enumeration<InetAddress> en) {
while (en.hasMoreElements()) {
final InetAddress address = en.nextElement();
if (!address.isLoopbackAddress()) {
if (address instanceof Inet6Address) {
ipv6Result.add(normalizeHostAddress(address));
} else {
ipv4Result.add(normalizeHostAddress(address));
}
}
}
}

private static String normalizeHostAddress(final InetAddress localHost) {
if (localHost instanceof Inet6Address) {
return "[" + localHost.getHostAddress() + "]";
} else {
return localHost.getHostAddress();
}
}


public static String parseChannelRemoteAddr(final Channel channel) {
if (null == channel) {
return "";
}
SocketAddress remote = channel.remoteAddress();
final String addr = remote != null ? remote.toString() : "";

if (addr.length() > 0) {
int index = addr.lastIndexOf("/");
if (index >= 0) {
return addr.substring(index + 1);
}

return addr;
}

return "";
}
}
Loading