advantageous / qbit

The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
http://advantageous.github.io/qbit/
Apache License 2.0
709 stars 140 forks source link

Add tags service discovery #737

Closed id-regis closed 8 years ago

id-regis commented 8 years ago

Currently it's impossible to retrieve tags from service discovery or pass tags to an endpoint, this pull request allow to set tags then register them into service discovery provider. It also add host in Registration domain from Consul

id-regis commented 8 years ago

Test are passing on my side only a timeout. But host registration still doesn't work in Consul due to a bug in Boon (https://github.com/boonproject/boon/issues/352)

RichardHightower commented 8 years ago

I will take a look.

RichardHightower commented 8 years ago

Are you sure?

The JsonMapper that ships with QBit is preconfigure to handle annotations.

This works

package io.advantageous.qbit.bugs;

import io.advantageous.boon.json.annotations.JsonProperty;
import io.advantageous.qbit.QBit;
import io.advantageous.qbit.json.JsonMapper;
import org.junit.Assert;
import org.junit.Test;

public class BoonBug352 {

    @Test
    public void test() {
        Registration registration = new Registration();
        registration.setName("name");
        registration.setHost("localhost");
        final JsonMapper mapper = QBit.factory().createJsonMapper();
        String jsonSource = "{\"Name\":\"name\",\"Address\":\"localhost\"}";
        Registration unserializedRegistration = mapper.fromJson(jsonSource, Registration.class);
        String json = mapper.toJson(unserializedRegistration);
        Assert.assertEquals(jsonSource, json);
    }

    public static class Registration {
        @JsonProperty("Name")
        private String name;
        @JsonProperty("Address")
        private String host;

        public String getName() {
            return name;
        }

        public Registration setName(String name) {
            this.name = name;
            return this;
        }

        public String getHost() {
            return host;
        }

        public Registration setHost(String host) {
            this.host = host;
            return this;
        }
    }

}

That said.. we should never output two fields. I will look into that.

RichardHightower commented 8 years ago

Ok.. I found the issue.

RichardHightower commented 8 years ago

Merge master into your branch and try it again.

id-regis commented 8 years ago

Thank for the patch it fixes the issue. Build and tests pass on my side.

RichardHightower commented 8 years ago

you are welcome.. thanks for contributing.