<dependency> <groupId>org.amdatu.remote</groupId> <artifactId>org.amdatu.remote.discovery.bonjour</artifactId> <version>3.1.0</version> </dependency> import org.amdatu.remote.discovery.Discovery; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class ServiceProvider implements BundleActivator { @Override public void start(BundleContext context) throws Exception { Discovery discovery = new org.amdatu.remote.discovery.bonjour.BonjourDiscovery(); String serviceName = "myService"; String serviceURL = "http://localhost:8080/myService"; discovery.register(serviceName, serviceURL); } @Override public void stop(BundleContext context) throws Exception { discovery.unregister(serviceName); } } import org.amdatu.remote.discovery.Discovery; import org.amdatu.remote.discovery.DiscoveredEndpoint; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class ServiceConsumer implements BundleActivator { @Override public void start(BundleContext context) throws Exception { Discovery discovery = new org.amdatu.remote.discovery.bonjour.BonjourDiscovery(); String serviceName = "myService"; DiscoveredEndpoint endpoint = discovery.discover(serviceName); MyService service = (MyService) endpoint.connect(); service.doSomething(); } @Override public void stop(BundleContext context) throws Exception { endpoint.disconnect(); } }


上一篇:
下一篇:
切换中文