Native microservice - create

Below is shown simple creation of native microservice with map container configured. First step is to create single module structure which is described here. Also add to dependencies library with JLupinAbstractMapApplicationContainer:

<dependency>
    <groupId>com.jlupin</groupId>
    <artifactId>jlupin-application-container-ext</artifactId>
    <version>1.6.1.0</version>
</dependency>

Then add classes shown below:

Creating interface

package com.example.interfaces;

public interface ExampleService {
    String getName();
}

Creating implementation

package com.example.impl;

import com.example.interfaces.ExampleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExampleServiceImpl implements ExampleService {
    private final static Logger logger = LoggerFactory.getLogger(ExampleServiceImpl.class);

    @Override
    public String getName() {
        logger.info("called getName() method");
        return "name";
    }
}

Interface is optional here (it is a good practice to create interface for every service) but is required for binary communication (generated proxy object is implementing interface). It is also a good practice to put interface in separate jar to not share your internal implementation with the others. More details about logging can be found in Logging chapter.

Remote sharing

package com.example.configuration;

import com.example.impl.ExampleServiceImpl;
import com.example.interfaces.ExampleService;
import com.jlupin.impl.container.application.map.JLupinAbstractMapApplicationContainer;
import com.jlupin.interfaces.configuration.microservice.container.application.JLupinAbstractApplicationContainerProducer;
import com.jlupin.interfaces.container.application.JLupinApplicationContainer;

public class JLupinConfiguration extends JLupinAbstractApplicationContainerProducer {
    @Override
    public JLupinApplicationContainer produceJLupinApplicationContainer() {
        return new JLupinAbstractMapApplicationContainer() {
            @Override
            public Map<String, Object> getBeansMap() {
                final Map<String, Object> beans = new HashMap<>();

                beans.put("jLupinRegularExpressionToRemotelyEnabled", getRemotelyBeanList());
                beans.put("exampleService", getExampleServiceBean());

                return beans;
            }
        };
    }

    private ExampleService getExampleServiceBean() {
        return new ExampleServiceImpl();
    }

    private List<String> getRemotelyBeanList() {
        List<String> list = new ArrayList<>();
        list.add("exampleService");
        return list;
    }
}

As you can see you don't need to use Spring IOC Container. Instead you can use simple map with beans. The important part is a bean named jLupinRegularExpressionToRemotelyEnabled. It is a list of regular expressions which are working as a masks for services available to JLupin Platform. What does it mean? For security reasons not all services are available for remote execution. And decision which are visible outside and which are not is being made by developer. Being specific, every object living inside container is a bean. And every bean should have it's own name. To determine which service should be exposed JLupin Platform takes all beans from application container and then check if this name matches any of regular expressions on bean jLupinRegularExpressionToRemotelyEnabled (this bean is a list). If it matches service is remotely enabled and can be called with remote execution.

You also need to tell JLupin which context to use. You do this by creating proper class and putting it's name in microservice configuration (configuration.yml).

[...]
APPLICATION:
  applicationContainerProducerClassName: 'com.example.configuration.JLupinConfiguration'
[...]

Full configuration.yml description can be found here.

And that's all code you need to write. Go to next section to manually or automatically upload your microservice.