Skip to content

Commit

Permalink
Fix connection name prefix for gatekeeper connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Serkan ÖZAL committed Dec 15, 2022
1 parent 49b18ea commit e51fb0a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer;
import io.thundra.merloc.broker.client.BrokerClient;
import io.thundra.merloc.broker.client.BrokerClientFactory;
import io.thundra.merloc.broker.client.BrokerConnectionType;
import io.thundra.merloc.broker.client.BrokerConstants;
import io.thundra.merloc.broker.client.BrokerCredentials;
import io.thundra.merloc.broker.client.BrokerMessage;
Expand Down Expand Up @@ -109,6 +110,7 @@ private static BrokerClient createBrokerClient(BrokerMessageCallback brokerMessa
BROKER_URL,
new BrokerCredentials().
withConnectionName(BROKER_CONNECTION_NAME).
withConnectionType(BrokerConnectionType.GATEKEEPER).
withApiKey(API_KEY),
brokerMessageCallback, null, null);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.thundra.merloc.aws.lambda.runtime.embedded.exception.ErrorCoded;
import io.thundra.merloc.aws.lambda.runtime.embedded.exception.HandlerExecutionException;
import io.thundra.merloc.broker.client.BrokerConnectionType;
import io.thundra.merloc.broker.client.BrokerConstants;
import io.thundra.merloc.broker.client.BrokerCredentials;
import io.thundra.merloc.broker.client.BrokerMessageCallback;
Expand Down Expand Up @@ -90,6 +91,7 @@ public void start() throws IOException {
BrokerCredentials credentials =
new BrokerCredentials().
withConnectionName(connectionName).
withConnectionType(BrokerConnectionType.CLIENT).
withApiKey(apiKey);

CompletableFuture connectedFuture = new CompletableFuture();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.thundra.merloc.broker.client;

/**
* @author serkan
*/
public enum BrokerConnectionType {

CLIENT(BrokerConstants.CLIENT_CONNECTION_NAME_PREFIX),
GATEKEEPER(BrokerConstants.GATEKEEPER_CONNECTION_NAME_PREFIX);

private final String connectionNamePrefix;

BrokerConnectionType(String connectionNamePrefix) {
this.connectionNamePrefix = connectionNamePrefix;
}

public String getConnectionNamePrefix() {
return connectionNamePrefix;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class BrokerCredentials {

private String connectionName;
private BrokerConnectionType connectionType;
private String apiKey;

public String getConnectionName() {
Expand All @@ -21,6 +22,19 @@ public BrokerCredentials withConnectionName(String connectionName) {
return this;
}

public BrokerConnectionType getConnectionType() {
return connectionType;
}

public void setConnectionType(BrokerConnectionType connectionType) {
this.connectionType = connectionType;
}

public BrokerCredentials withConnectionType(BrokerConnectionType connectionType) {
this.connectionType = connectionType;
return this;
}

public String getApiKey() {
return apiKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.thundra.merloc.broker.client.BrokerConnectionType;
import io.thundra.merloc.broker.client.BrokerConstants;
import io.thundra.merloc.broker.client.BrokerCredentials;
import io.thundra.merloc.broker.client.BrokerEnvelope;
Expand Down Expand Up @@ -107,9 +108,13 @@ public OkHttpWebSocketBrokerClient(String url,

private static String getFullConnectionName(BrokerCredentials brokerCredentials) {
String connectionName = brokerCredentials.getConnectionName();
BrokerConnectionType connectionType = brokerCredentials.getConnectionType();
if (connectionType == null) {
throw new IllegalArgumentException("No connection type was specified in broker credentials");
}
String apiKey = brokerCredentials.getApiKey();
if (connectionName != null) {
String fullConnectionName = BrokerConstants.CLIENT_CONNECTION_NAME_PREFIX + connectionName;
String fullConnectionName = connectionType.getConnectionNamePrefix() + connectionName;
if (apiKey != null) {
fullConnectionName += BrokerConstants.CONNECTION_API_KEY_SEPARATOR + apiKey;
}
Expand Down

0 comments on commit e51fb0a

Please sign in to comment.