Skip to content

Latest commit

 

History

History
161 lines (139 loc) · 4.54 KB

README.md

File metadata and controls

161 lines (139 loc) · 4.54 KB

logo

RMI (Remote Method Invocation) framework supporting service discovery out-of-box among devices within same network considering IOT(internet of device) proof-of-concept project

Codacy Badge Build Status

Features

  1. Zero configuration for service integration based on RMI and Service Discovery
  2. Simple APIs

discover and request service with just a few API calls

  1. Support large blob as method parameter or response

yarmi supports blob exchange between client and server by default with BlobSession which exposes familiar read / write APIs

How-To

Using with Maven

  1. Add Maven Repository
<repositories>
    <repository>
        <id>yarmi-core</id>
        <name>yarmi</name>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>https://raw.githubusercontent.com/fritzprix/yarmi/releases</url>
    </repository>
</repositories>
  1. Add dependency
<dependencies>
        <dependency>
            <groupId>net.doodream</groupId>
            <artifactId>yarmi-core</artifactId>
            <version>0.1.1</version>
        </dependency>
            <dependency>
                <groupId>net.doodream.yarmi</groupId>
                <artifactId>sdp-mdns</artifactId>
                <version>0.1.1</version>
            </dependency>
</dependencies>

Using with Gradle

  1. Add Repository
allprojects {
    repositories {
        ...
        maven {
            url 'https://raw.githubusercontent.com/fritzprix/yarmi/releases'
        }
        maven {
            url 'https://raw.githubusercontent.com/fritzprix/yarmi/snapshots'
        }
        ...
    }
}
  1. Add Dependency
dependencies {
...
    implementation 'net.doodream:yarmi-core:0.1.1'
    implementation 'net.doodream.yarmi:sdp-mdns:0.1.1'
    implementation 'org.jmdns:jmdns:3.5.1'

...
}

Build Service (Server)

  1. Declare controller stubs with RMIExpose annotation
public interface TestController {

    @RMIExpose
    Response<String> echo(String message);
} 
  1. Implement Controller
public class TestControllerImpl implements TestController {


    @Override
    public Response<String> echo(String message) {
        return Response.success(message);
    }
}  
  1. Declare your service with route configuration
@Service(name = "test-service",
         provider = "com.example",
         params = {
            @AdapterParam(key=TcpServiceAdapter.PARAM_PORT, value = "6644")
         })
public class TestService {

    @Controller(path = "/test", version = 1, module = TestControllerImpl.class)
    TestController controller;
}
  1. Start service & advertise it
    final RMIService service = RMIService.create(TestService.class);
    final ServiceRegistry registry = MDnsServiceRegistry.create();
    
    service.listen();
    registry.register(service);
    registry.start();

Build Client

  1. Discover service & create client
    // build target service information
    final ServiceDiscovery discovery = MDnsServiceDiscovery.create();
    discovery.start(TestService.class, new ServiceDiscoveryListener() {
        @Override
        public void onDiscoveryStarted() {
            // discovery started
        }

        @Override
        public void onServiceDiscovered(RMIServiceInfo service) {
            // new service discovered
            Object client = RMIClient.create(servce, TestService.class, new Class[] {
                    TestController.class
            });
            // cast client proxy into interface of interest
            TestController controller = (TestController) client;
            // and use it 
            Response<String> response = controller.echo("Hello");
            if(response.isSucessful()) {
                // successfully RMI handled and response received successfully
                System.out.println(response.getBody());
            }
        }

        @Override
        public void onDiscoveryFinished(int i, Throwable throwable) {
            // service discovery finished
        }
    });

License

Apache License, Version 2.0