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

Adding DNS support for QBit Service Discovery using Vertx3. #420

Merged
merged 1 commit into from
Sep 30, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@
import io.advantageous.qbit.events.EventManager;
import io.advantageous.qbit.events.EventManagerBuilder;
import io.advantageous.qbit.events.impl.BoonEventBusProxyCreator;
import io.advantageous.qbit.events.spi.EventConnector;
import io.advantageous.qbit.http.HttpTransport;
import io.advantageous.qbit.http.client.HttpClient;
import io.advantageous.qbit.http.config.HttpServerOptions;
import io.advantageous.qbit.http.server.HttpServer;
import io.advantageous.qbit.json.JsonMapper;
import io.advantageous.qbit.message.MethodCall;
import io.advantageous.qbit.message.MethodCallBuilder;
import io.advantageous.qbit.message.Request;
import io.advantageous.qbit.message.Response;
import io.advantageous.qbit.queue.Queue;
import io.advantageous.qbit.queue.QueueBuilder;
import io.advantageous.qbit.sender.Sender;
import io.advantageous.qbit.sender.SenderEndPoint;
Expand All @@ -49,7 +44,6 @@
import io.advantageous.qbit.service.impl.BoonServiceMethodCallHandler;
import io.advantageous.qbit.service.impl.CallbackManager;
import io.advantageous.qbit.service.impl.ServiceBundleImpl;
import io.advantageous.qbit.service.impl.ServiceQueueImpl;
import io.advantageous.qbit.service.stats.StatsCollector;
import io.advantageous.qbit.spi.*;
import io.advantageous.qbit.system.QBitSystemManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* QBit - The Microservice lib for Java : JSON, WebSocket, REST. Be The Web!
*/

package io.advantageous.qbit.boon;
package io.advantageous.qbit.service;

import io.advantageous.boon.core.Str;
import io.advantageous.boon.primitive.CharBuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
* QBit - The Microservice lib for Java : JSON, WebSocket, REST. Be The Web!
*/

package io.advantageous.qbit.boon;
package io.advantageous.qbit.service;

import io.advantageous.qbit.QBit;
import io.advantageous.qbit.client.ServiceProxyFactory;
import io.advantageous.qbit.message.MethodCall;
import io.advantageous.qbit.service.EndPoint;
import org.junit.Before;
import org.junit.Test;

Expand Down
26 changes: 26 additions & 0 deletions qbit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,32 @@ project('vertx') {
}


project('service-discovery') {


ext {
vertxVersion = '3.0.0'
}

dependencies {
compile project(':qbit:boon')
compile project(':qbit:core')
compile group: 'io.vertx', name: 'vertx-core', version: vertxVersion
compile group: 'io.vertx', name: 'vertx-web', version: vertxVersion
testCompile project(':qbit:test-support')
}

uploadArchives {
repositories {
mavenDeployer {
pom.project {
description 'Vertx support for qbit'
}
}
}
}
}


project('consul-client') {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public class EventManagerBuilder {
private StatsCollector statsCollector;
public static EventConnector DEFAULT_NO_EVENT_CONNECTOR = event -> {};
public static StatsCollector DEFAULT_NO_STATS_COLLECTOR = new StatsCollector() {};

private final Logger logger = LoggerFactory.getLogger(EventManagerBuilder.class);

Factory factory;
private Factory factory;


public static EventManagerBuilder eventManagerBuilder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.advantageous.qbit.reactive;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

Expand Down Expand Up @@ -52,6 +56,31 @@ public <T> CallbackBuilder setCallback(Class<T> returnType, Callback<T> callback
}


public <T> CallbackBuilder setCallbackReturnsList(Class<T> componentClass, Callback<List<T>> callback) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change these to with.

this.callback = callback;
return this;
}

public <T> CallbackBuilder setCallbackReturnsSet(Class<T> componentClass, Callback<Set<T>> callback) {
this.callback = callback;
return this;
}

public <T> CallbackBuilder setCallbackReturnsCollection(Class<T> componentClass, Callback<Collection<T>> callback) {
this.callback = callback;
return this;
}

public <K, V> CallbackBuilder setCallbackReturnsMap(Class<K> keyClass, Class<V> valueClass,
Callback<Map<K, V>> callback) {
this.callback = callback;
return this;
}





public Runnable getOnTimeout() {
return onTimeout;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,84 @@
package io.advantageous.qbit.service.discovery;

import io.advantageous.boon.core.Lists;
import io.advantageous.boon.core.Sys;
import io.advantageous.qbit.service.health.HealthStatus;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

import static io.advantageous.qbit.service.discovery.ServiceDiscovery.uniqueString;

/**
* Service Definition
* Contains a healthStatus, unique id, name, host, port and a timeToLive in seconds.
* This describes all parts of a service as far as something like a ServiceDiscovery system like
* [Consul](https://consul.io/) is concerned.
*
* The `timeToLive` field is for ttl checkins if the underlying system supports it.
*
* The `HealthStatus` represents the current state of this system as returned from the remote
* service discovery system.
*
* created by rhightower on 3/23/15.
*/
public class EndpointDefinition {


/**
* Current health status.
*/
private final HealthStatus healthStatus;

/**
* Unique id of the system.
*/
private final String id;

/**
* Name of the service, i.e., EventBus, StatsEngine, etc.
*/
private final String name;

/**
* Host name.
*/
private final String host;

/**
* Port of the service.
*/
private final int port;

/**
* Time to live: how long until this service has to check in with the remote service discovery
* system if applicable. Whether this is used or needed depends on the underlying service discovery system.
*/
private final long timeToLive;


/**
* Find host
* @return hostname
*/
static String findHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
throw new IllegalStateException("unable to find host name");
}
}


/**
* Create a new one with default TTL of 20 seconds.
* @param healthStatus healthStatus
* @param id id
* @param name name
* @param host post
* @param port port
*/
public EndpointDefinition(
final HealthStatus healthStatus,
final String id,
Expand All @@ -31,9 +90,36 @@ public EndpointDefinition(
this.name = name;
this.host = host;
this.port = port;
this.timeToLive = 20L;
this.timeToLive = Sys.sysProp(EndpointDefinition.class.getName()+".timeToLive", 20L);
}

/**
* Create a new one with default TTL of 20 seconds.
* @param name name
* @param host post
* @param port port
*/
public EndpointDefinition(
final String name,
final String host,
final int port) {
this.healthStatus = HealthStatus.PASS;
this.id = name + "-" + port + "-" + host.replace('.', '-');
this.name = name;
this.host = host;
this.port = port;
this.timeToLive = Sys.sysProp(EndpointDefinition.class.getName()+".timeToLive", 20L);
}


/**
* Create a new one with default TTL of 20 seconds.
* @param healthStatus healthStatus
* @param id id
* @param name name
* @param host post
* @param port port
*/
public EndpointDefinition(
final HealthStatus healthStatus,
final String id,
Expand All @@ -49,10 +135,46 @@ public EndpointDefinition(
this.timeToLive = timeToLive;
}

/**
* Creates a list of service definitions.
* @param endpointDefinitions vararg array of service definitions
* @return list of service definitions
*/
public static List<EndpointDefinition> serviceDefinitions(final EndpointDefinition... endpointDefinitions) {
return Lists.list(endpointDefinitions);
}

/**
* Creates a EndpointDefinition for a service, i.e., a serviceDefinition.
* @param name name
* @return serviceDefinition
*/
public static EndpointDefinition serviceDefinition(final String name) {

return new EndpointDefinition(HealthStatus.PASS,
name + "-" + uniqueString(0), name, findHostName(), 0);
}

/**
* Creates a EndpointDefinition for a service, i.e., a serviceDefinition.
* @param name service name
* @param port port
* @return serviceDefinition
*/
public static EndpointDefinition serviceDefinition(final String name, int port) {

return new EndpointDefinition(HealthStatus.PASS,
name + "-" + uniqueString(port), name, findHostName(), 0);
}

/**
* Creates a EndpointDefinition for a service, i.e., a serviceDefinition.
* @param id id
* @param name name
* @param host host
* @param port port
* @return EndpointDefinition
*/
public static EndpointDefinition serviceDefinition(
final String id,
final String name,
Expand All @@ -63,6 +185,13 @@ public static EndpointDefinition serviceDefinition(
id, name, host, port);
}

/**
* Creates a EndpointDefinition for a service, i.e., a serviceDefinition.
* @param name name
* @param host host
* @param port port
* @return serviceDefinition
*/
public static EndpointDefinition serviceDefinition(
final String name,
final String host,
Expand All @@ -73,6 +202,12 @@ public static EndpointDefinition serviceDefinition(
}


/**
* Creates a EndpointDefinition for a service, i.e., a serviceDefinition.
* @param name name
* @param host host
* @return serviceDefinition
*/
public static EndpointDefinition serviceDefinition(
final String name,
final String host
Expand All @@ -83,11 +218,18 @@ public static EndpointDefinition serviceDefinition(
}



/**
* Creates a EndpointDefinition for a service, i.e., a serviceDefinition.
* @param id id
* @param name name
* @param host host
* @return EndpointDefinition
*/
public static EndpointDefinition serviceDefinitionWithId(
final String name,
final String host,
final String id
) {
final String id) {

return new EndpointDefinition(HealthStatus.PASS,
id, name, host, 0);
Expand Down
Loading