You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "jasonjoo2010 (GitHub)" <gi...@apache.org> on 2019/09/26 07:23:20 UTC

[GitHub] [dubbo] jasonjoo2010 commented on issue #5115: how to get dubbo instance's ip, port and timestamp when started?

> there is my demo
> `
> public static void main(String[] args) throws IOException {
> //may start multiple main process
> System.out.println("start test......");
> ApplicationConfig application = new ApplicationConfig();
> RegistryConfig registry = new RegistryConfig();
> application.setName("test");
> registry.setAddress("127.0.0.1:2181");
> registry.setProtocol("zookeeper");
> ProtocolConfig protocol = new ProtocolConfig();
> protocol.setName("dubbo");
> //random port, i don't know now
> protocol.setPort(-1);
> protocol.setThreads(200);
> ServiceConfig service1 = new ServiceConfig<>();
> service1.setApplication(application);
> service1.setRegistry(registry);
> service1.setProtocol(protocol);
> service1.setInterface(TestService.class);
> service1.setRef(new TestServiceImpl());
> service1.export();
> // i need get the port, ip and start time as key save to log or mysql now,why need save to mysql ,because when the process crashe, other process can get data related to this key doing aftercare,please tell me how to get port, ip and start time
> 
> ```
>     System.in.read();
> 
> }
> ```
> 
> `

It still depends on actual use case.
In your case shown above, one of the solutions is:

```java
URL url = service1.toUrl();
System.out.println(url.getProtocol() + " => " + url.getPort());
```

result: 

```
dubbo => 20880
```

[ Full content available at: https://github.com/apache/dubbo/issues/5115 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org