• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NotRegisteredException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.orbitz.consul.NotRegisteredException的典型用法代码示例。如果您正苦于以下问题:Java NotRegisteredException类的具体用法?Java NotRegisteredException怎么用?Java NotRegisteredException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NotRegisteredException类属于com.orbitz.consul包,在下文中一共展示了NotRegisteredException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: registerMyself

import com.orbitz.consul.NotRegisteredException; //导入依赖的package包/类
private void registerMyself() throws NotRegisteredException, IOException {
    AgentClient agentClient = getConsul().agentClient();

    if (!agentClient.isRegistered(consulProperties.getServiceId())) {
        registerHeartbeat();
    }

    log.info("writing service access properties");
    KeyValueClient kvClient = getConsul().keyValueClient();
    Map<String, String> accessProperties = new HashMap<>();
    String serverName = InetAddress.getLocalHost().getHostName();
    accessProperties.put("hostname", serverName);
    accessProperties.put("ip", dnsResolver.readNonLoopbackLocalAddress());
    String port = String.valueOf(serverProperties.getPort());
    accessProperties.put("port", port);
    accessProperties.put("username", securityProperties.getUser().getName());
    accessProperties.put("password", securityProperties.getUser().getPassword());

    // read current access values and add ourselves
    String accessKey = consulProperties.getServiceName() + "/access/" + serverName + ":" + port;
    kvClient.putValue(accessKey, mapper.writeValueAsString(accessProperties));
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:23,代码来源:Consul4Spring.java


示例2: keepAlive

import com.orbitz.consul.NotRegisteredException; //导入依赖的package包/类
/**
 * changes the heartbeat check to PASS in a configurable rate. The default rate is 15 minutes. The heartbeat check
 * is defined with a grace period of 2 heartbeats before it sets itself to FAIL.
 */
@Override
public void keepAlive() {
    try {
        AgentClient agentClient = getConsul().agentClient();
        // the heartbeat is the service itself, not a check - that's why we "pass" it and not "check" it
        agentClient.pass(toUniqueName("heartbeat"));
        log.info("[check heartbeat]: PASS");
    } catch (NotRegisteredException e) {
        log.error("[check heartbeat]: FAIL " + e.getMessage());
        log.error("can't mark heartbeat as PASS", e);
        registerHeartbeat();
    }
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:18,代码来源:Consul4Spring.java


示例3: registerAndCheckServiceTest

import com.orbitz.consul.NotRegisteredException; //导入依赖的package包/类
@Test
public void registerAndCheckServiceTest() throws NotRegisteredException {
    injects();
    final String serviceName = "MyService";
    final String serviceId = "1";
    agentClient.register(8080, 3L, serviceName, serviceId);
    agentClient.pass(serviceId);
    agentClient.deregister(serviceId);
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:10,代码来源:ConsulTests.java


示例4: fullPluginLifecycleWithDefaultConfiguration

import com.orbitz.consul.NotRegisteredException; //导入依赖的package包/类
@Test
public void fullPluginLifecycleWithDefaultConfiguration() throws ExecutionException, InterruptedException {

    // dummy consul client
    Consul consul = mock(Consul.class);
    AgentClient agentClient = mock(AgentClient.class);
    when(consul.agentClient()).thenReturn(agentClient);

    // empty config
    ConfigurationReader configurationReader = mock(ConfigurationReader.class);
    Properties properties = new Properties();
    when(configurationReader.getProperties()).thenReturn(properties);
    Configuration configuration = new Configuration(configurationReader);

    PluginExecutorService pluginExecutorService = mock(PluginExecutorService.class);

    ConsulDiscoveryCallback callback = new ConsulDiscoveryCallback(consul, configuration, pluginExecutorService);
    callback.init("clusternode1", new ClusterNodeAddress("clusternode1-hostname", 1234));

    // check if registration job gets scheduled
    ArgumentCaptor<Runnable> runnableArgument = ArgumentCaptor.forClass(Runnable.class);
    verify(pluginExecutorService, times(2)).scheduleAtFixedRate(runnableArgument.capture(), anyLong(), eq(60l), eq(TimeUnit.SECONDS));

    // run registration job
    Runnable registrationRunnable = runnableArgument.getAllValues().get(0);
    Runnable updateRunnable = runnableArgument.getAllValues().get(1);

    registrationRunnable.run();

    // verify service registration
    ArgumentCaptor<Registration> argument = ArgumentCaptor.forClass(Registration.class);
    verify(agentClient).register(argument.capture(), any());


    Registration registration = argument.getValue();
    assertEquals("cluster-discovery-hivemq", registration.getName());
    assertEquals("clusternode1-hostname", registration.getAddress().get());
    assertEquals(Integer.valueOf(1234), registration.getPort().get());
    assertEquals("cluster-discovery-hivemq", registration.getName());

    String registrationId = registration.getId();
    assertThat(registrationId).containsOnlyDigits();
    assertEquals(1, registration.getChecks().size());

    Registration.RegCheck regCheck = registration.getChecks().get(0);
    assertEquals("120s", regCheck.getTtl().get());

     // run updater job and check consul service pass call
    updateRunnable.run();
    try {
        verify(agentClient).pass(eq(registrationId));
    } catch (NotRegisteredException e) {
        throw new RuntimeException(e);
    }

    HealthClient healthClient = mock(HealthClient.class);
    List<ServiceHealth> nodes = new ArrayList<>();

    Service service = ImmutableService.builder()
            .address("host1")
            .id("not important")
            .service("doesnt matter")
            .port(5678).build();

    Node node = ImmutableNode.builder().node("node1").address("address1").build();
    ServiceHealth serviceHealth = ImmutableServiceHealth.builder().service(service).node(node).build();

    nodes.add(serviceHealth);
    ConsulResponse response = new ConsulResponse(nodes, 0, true, BigInteger.ZERO);
    when(healthClient.getHealthyServiceInstances(anyString(), ArgumentMatchers.<ImmutableQueryOptions>any())).thenReturn(response);
    when(consul.healthClient()).thenReturn(healthClient);

    List<ClusterNodeAddress> addresses = callback.getNodeAddresses().get();
    assertEquals(1, addresses.size());
    assertEquals("host1", addresses.get(0).getHost());
    assertEquals(5678, addresses.get(0).getPort());

    callback.destroy();
    verify(agentClient).deregister(eq(registrationId));
}
 
开发者ID:pellepelster,项目名称:hivemq-consul-cluster-discovery,代码行数:81,代码来源:ConsulDiscoveryCallbackTest.java


示例5: checkTtl

import com.orbitz.consul.NotRegisteredException; //导入依赖的package包/类
private void checkTtl() throws NotRegisteredException {
  if (!clientOnly) {
    CONSUL_HOLDER.checkTtl(consulServiceId);
  }
}
 
开发者ID:squark-io,项目名称:active-mq-consul-discovery,代码行数:6,代码来源:ConsulDiscoveryAgent.java



注:本文中的com.orbitz.consul.NotRegisteredException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TextConsolePage类代码示例发布时间:2022-05-23
下一篇:
Java MpegAudioFileReader类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap