ETCD how to

17 views
Skip to first unread message

Stanislav Fujdiar

unread,
Aug 26, 2015, 8:47:22 AM8/26/15
to fabric3
Hi Jim,

is there some example or how to use ETCD in fabric3 3.0.0. I can't find code on git or in documentation. I want to try cluster configuration with 3.0.0 version.

thanks

Jim Marino

unread,
Aug 31, 2015, 12:11:12 PM8/31/15
to fabric3
Hi Stanislav!

Sorry for the delay (out on vacation).

We don't yet have version 3.0 documented but this should get you started. It would be great to get some testing, particularly around leader-election which we had to implement on top of etcd.

To install the etcd extension, simply place the JAR in the runtime extensions directory and start the runtime in NODE mode.

To have a property sourced from etcd, defining it using the external syntax ${..}:


@Property
@Source("${foo}")

public void setFoo(String foo) {

   this.foo = foo;

}

These properties are re-injectable and the search order is:

  1. External key/value store such as etcd (document we also support etc)
  2. An environment property
  3. A VM property

In etcd, all configuration keys specified by @Source are placed under /[domain]/configuration in etc. In the above example, the foo key will be at v2/keys/domain/configuration/foo.

To put to etcd using curl:

curl -L http://127.0.0.1:4001/v2/keys/domain/configuration/foo -XPUT -d value="Hello world3"

Delete is also supported (null will be injected):

curl -L http://127.0.0.1:4001/v2/keys/domain/configuration/foo -XDELETE


Complex JSON types are also supported:


public class Bar {

    private String bar;

    public String getBar() {

       return bar;

    }

    public void setBar(String bar) {

        this.bar = bar;

    }

}


public class TestComponent {

   protected Bar bar;

    @Property

    @Source("${bar}")

    public void setBar(Bar bar) {

        String oldBar = this.bar == null ? "null" : this.bar.getBar();

        String newBar = bar == null ? "null" : bar.getBar();

        System.out.println("Bar changed:::::::::::::" +oldBar + ":" + newBar);

        this.bar = bar;

    }


And to put the complex type:

 curl -L http://127.0.0.1:4001/v2/keys/domain/configuration/bar -XPUT -d value="{\"bar\":\"bar0\"}"



Let me know if this helps and how you get along.

Jim




--
You received this message because you are subscribed to the Google Groups "fabric3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabric3+u...@googlegroups.com.
To post to this group, send email to fab...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fabric3/85903e28-3c1e-486e-bfec-be1cc06f3f50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages