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

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

- [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [ ] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.

### Environment

* Dubbo version: 2。6。5
* Operating System version: ubuntu
* Java version: 1.8

### Steps to reproduce this issue
hi, I have a requirement now, when a dubbo application is started, I need get the dubbo instance's ip, port and timestamp, then that message as the dubbo instance's unique key save to mysql ,but i have not a good idea to get that message,please tell me how to get the message ? thanks



Pls. provide [GitHub address] to reproduce this issue.

### Expected Result

What do you expected from the above steps?

### Actual Result

What actually happens?

If there is an exception, please attach the exception trace:

```
Just put your stack trace here!
```


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

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

Posted by "StevenKin (GitHub)" <gi...@apache.org>.
thank you very much!!

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

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

Posted by "StevenKin (GitHub)" <gi...@apache.org>.
there is my demo
`//may start multiple main process 
public static void main(String[] args) throws IOException {
        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<TestService> 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();

    }`

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


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

Posted by "StevenKin (GitHub)" <gi...@apache.org>.
there is my demo
`
//may start multiple main process 
public static void main(String[] args) throws IOException {
        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<TestService> 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();

    }
`

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


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

Posted by "jasonjoo2010 (GitHub)" <gi...@apache.org>.
> 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