com.orbitz.consul.option.QueryOptions Java Examples
The following examples show how to use
com.orbitz.consul.option.QueryOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CatalogWatcher.java From thorntail with Apache License 2.0 | 6 votes |
private void setupWatcher(String serviceName) { if (watchers.containsKey(serviceName)) { return; } QueryOptions options = ImmutableQueryOptions.builder() .build(); ServiceHealthCache healthCache = ServiceHealthCache.newCache( this.healthClientInjector.getValue(), serviceName, true, options, 5 ); try { healthCache.addListener(new ServiceCacheListener(serviceName, this.topologyManagerInjector.getValue())); healthCache.start(); healthCache.awaitInitialized(1, TimeUnit.SECONDS); this.watchers.put(serviceName, healthCache); } catch (Exception e) { ConsulTopologyMessages.MESSAGES.errorSettingUpCatalogWatcher(serviceName, e); } }
Example #2
Source File: ConsulUtility.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 5 votes |
/** * Method to build an ACL token in a query option. * * @param token * @return QueryOption */ public static QueryOptions getAclToken(String token){ if(token == null || token.trim().isEmpty()){ return ImmutableQueryOptions.BLANK; } //ACL token for registering as a service on consul, check health and get service catalog ImmutableQueryOptions.Builder optionBuilder = ImmutableQueryOptions.builder().token(token); return optionBuilder.build(); }
Example #3
Source File: ConsulTests.java From nano-framework with Apache License 2.0 | 4 votes |
@Test public void blockingCallTest() throws InterruptedException { injects(); keyValueClient.putValue(KEY, VALUE); final StringBuilder builder = new StringBuilder(); final ConsulResponseCallback<Optional<Value>> callback = new ConsulResponseCallback<Optional<Value>>() { final AtomicReference<BigInteger> index = new AtomicReference<BigInteger>(null); @Override public void onComplete(final ConsulResponse<Optional<Value>> consulResponse) { if (consulResponse.getResponse().isPresent()) { final Value v = consulResponse.getResponse().get(); builder.setLength(0); builder.append(v.getValueAsString().get()); } index.set(consulResponse.getIndex()); watch(); } void watch() { keyValueClient.getValue(KEY, QueryOptions.blockMinutes(5, index.get()).build(), this); } @Override public void onFailure(final Throwable throwable) { LOGGER.error("Error encountered", throwable); watch(); } }; keyValueClient.getValue(KEY, QueryOptions.blockMinutes(5, new BigInteger("0")).build(), callback); Thread.sleep(1000); keyValueClient.putValue(KEY, NEW_VALUE); Thread.sleep(500); Assert.assertEquals(builder.toString(), NEW_VALUE); keyValueClient.deleteKey(KEY); final String delValue = keyValueClient.getValueAsString(KEY).or(DELETED); Assert.assertEquals(delValue, DELETED); }