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

Java sdk update #610

Merged
merged 4 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions eventmesh-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ dependencies {

implementation "com.lmax:disruptor"

implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.core:jackson-core"
implementation "com.fasterxml.jackson.core:jackson-annotations"
api "com.fasterxml.jackson.core:jackson-databind"
api "com.fasterxml.jackson.core:jackson-core"
api "com.fasterxml.jackson.core:jackson-annotations"

implementation "org.apache.httpcomponents:httpclient"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import lombok.Builder;
import lombok.Data;

import java.util.Objects;

@Data
@Builder
public class UserAgent {
Expand All @@ -40,4 +42,70 @@ public class UserAgent {
@Builder.Default
private int unack = 0;

public UserAgent() {
}

public UserAgent(String env, String subsystem, String path, int pid, String host, int port, String version,
String username, String password, String idc, String producerGroup, String consumerGroup,
String purpose, int unack) {
this.env = env;
this.subsystem = subsystem;
this.path = path;
this.pid = pid;
this.host = host;
this.port = port;
this.version = version;
this.username = username;
this.password = password;
this.idc = idc;
this.producerGroup = producerGroup;
this.consumerGroup = consumerGroup;
this.purpose = purpose;
this.unack = unack;
}

@Override
public String toString() {
return String.format(
"UserAgent{env='%s'subsystem='%s', path='%s', pid=%d, host='%s', port=%d, version='%s', idc='%s', purpose='%s', unack='%d'}",
env, subsystem, path, pid, host, port, version, idc, purpose, unack);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

UserAgent userAgent = (UserAgent) o;

if (pid != userAgent.pid) return false;
if (port != userAgent.port) return false;
if (unack != userAgent.unack) return false;
if (!Objects.equals(subsystem, userAgent.subsystem)) return false;
if (!Objects.equals(path, userAgent.path)) return false;
if (!Objects.equals(host, userAgent.host)) return false;
if (!Objects.equals(purpose, userAgent.purpose)) return false;
if (!Objects.equals(version, userAgent.version)) return false;
if (!Objects.equals(username, userAgent.username)) return false;
if (!Objects.equals(password, userAgent.password)) return false;
if (!Objects.equals(env, userAgent.env)) return false;
return Objects.equals(idc, userAgent.idc);
}

@Override
public int hashCode() {
int result = subsystem != null ? subsystem.hashCode() : 0;
result = 31 * result + (path != null ? path.hashCode() : 0);
result = 31 * result + pid;
result = 31 * result + (host != null ? host.hashCode() : 0);
result = 31 * result + (purpose != null ? purpose.hashCode() : 0);
result = 31 * result + port;
result = 31 * result + (version != null ? version.hashCode() : 0);
result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (idc != null ? idc.hashCode() : 0);
result = 31 * result + (env != null ? env.hashCode() : 0);
result = 31 * result + unack;
return result;
}
}
4 changes: 4 additions & 0 deletions eventmesh-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* limitations under the License.
*/

configurations {
implementation.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}

dependencies {
implementation project(":eventmesh-sdk-java")
implementation project(":eventmesh-common")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.cloudevents.core.builder.CloudEventBuilder;
import io.cloudevents.core.v03.CloudEventV03;
import io.cloudevents.core.v1.CloudEventV1;

import org.apache.commons.lang3.StringUtils;

import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.protocol.http.body.message.SendMessageBatchV2RequestBody;
import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
Expand Down Expand Up @@ -42,37 +44,37 @@ public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHan
if (StringUtils.equals(SpecVersion.V1.toString(), protocolVersion)) {
event = JsonUtils.deserialize(content, CloudEventV1.class);
event = CloudEventBuilder.from(event)
.withExtension(ProtocolKey.REQUEST_CODE, code)
.withExtension(ProtocolKey.ClientInstanceKey.ENV, env)
.withExtension(ProtocolKey.ClientInstanceKey.IDC, idc)
.withExtension(ProtocolKey.ClientInstanceKey.IP, ip)
.withExtension(ProtocolKey.ClientInstanceKey.PID, pid)
.withExtension(ProtocolKey.ClientInstanceKey.SYS, sys)
.withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username)
.withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd)
.withExtension(ProtocolKey.VERSION, version.getVersion())
.withExtension(ProtocolKey.LANGUAGE, language)
.withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType)
.withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc)
.withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion)
.build();
.withExtension(ProtocolKey.REQUEST_CODE, code)
.withExtension(ProtocolKey.ClientInstanceKey.ENV, env)
.withExtension(ProtocolKey.ClientInstanceKey.IDC, idc)
.withExtension(ProtocolKey.ClientInstanceKey.IP, ip)
.withExtension(ProtocolKey.ClientInstanceKey.PID, pid)
.withExtension(ProtocolKey.ClientInstanceKey.SYS, sys)
.withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username)
.withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd)
.withExtension(ProtocolKey.VERSION, version.getVersion())
.withExtension(ProtocolKey.LANGUAGE, language)
.withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType)
.withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc)
.withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion)
.build();
} else if (StringUtils.equals(SpecVersion.V03.toString(), protocolVersion)) {
event = JsonUtils.deserialize(content, CloudEventV03.class);
event = CloudEventBuilder.from(event)
.withExtension(ProtocolKey.REQUEST_CODE, code)
.withExtension(ProtocolKey.ClientInstanceKey.ENV, env)
.withExtension(ProtocolKey.ClientInstanceKey.IDC, idc)
.withExtension(ProtocolKey.ClientInstanceKey.IP, ip)
.withExtension(ProtocolKey.ClientInstanceKey.PID, pid)
.withExtension(ProtocolKey.ClientInstanceKey.SYS, sys)
.withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username)
.withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd)
.withExtension(ProtocolKey.VERSION, version.getVersion())
.withExtension(ProtocolKey.LANGUAGE, language)
.withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType)
.withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc)
.withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion)
.build();
.withExtension(ProtocolKey.REQUEST_CODE, code)
.withExtension(ProtocolKey.ClientInstanceKey.ENV, env)
.withExtension(ProtocolKey.ClientInstanceKey.IDC, idc)
.withExtension(ProtocolKey.ClientInstanceKey.IP, ip)
.withExtension(ProtocolKey.ClientInstanceKey.PID, pid)
.withExtension(ProtocolKey.ClientInstanceKey.SYS, sys)
.withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username)
.withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd)
.withExtension(ProtocolKey.VERSION, version.getVersion())
.withExtension(ProtocolKey.LANGUAGE, language)
.withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType)
.withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc)
.withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion)
.build();
}
return event;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,11 @@ public void onSuccess(CloudEvent event) {
HttpCommand succ = asyncContext.getRequest().createHttpCommandResponse(
sendMessageResponseHeader,
SendMessageResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(),
JsonUtils.serialize(new SendMessageResponseBody.ReplyMessage(topic,
rtnMsg))));
JsonUtils.serialize(SendMessageResponseBody.ReplyMessage.builder()
.topic(topic)
.body(rtnMsg)
.properties(EventMeshUtil.getEventProp(event))
.build())));
asyncContext.onComplete(succ, handler);
} catch (Exception ex) {
HttpCommand err = asyncContext.getRequest().createHttpCommandResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.eventmesh.protocol.api.ProtocolPluginFactory;
import org.apache.eventmesh.runtime.constants.EventMeshConstants;
import org.apache.eventmesh.runtime.core.protocol.http.consumer.HandleMsgContext;
import org.apache.eventmesh.runtime.util.OMSUtil;
import org.apache.eventmesh.runtime.util.EventMeshUtil;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
Expand Down Expand Up @@ -150,7 +150,7 @@ public void tryHTTPRequest() {
body.add(new BasicNameValuePair(PushMessageRequestBody.TOPIC, handleMsgContext.getTopic()));

body.add(new BasicNameValuePair(PushMessageRequestBody.EXTFIELDS,
JsonUtils.serialize(OMSUtil.getEventProp(handleMsgContext.getEvent()))));
JsonUtils.serialize(EventMeshUtil.getEventProp(handleMsgContext.getEvent()))));

try {
builder.setEntity(new UrlEncodedFormEntity(body));
Expand Down
Loading