Integrate external service into micro-service system


In the big picture of micro-service system, it’s completely feasible sometimes we decide to leverage existing facility service instead of build that service. By this way, we could bring the system to the market sooner.

During integration the particular external services, we recognized that the goal goes beyond the leverage the functional feature provided by that services. The side effect of the integration is we gradually become dependent on those services, we could not witch to the other service which probably provides a better quality of functionality. Hence, how to keep the system portable enough to move forward with other service providers is one of technical challenge.

Continue reading

Sponsored Post Learn from the experts: Create a successful blog with our brand new courseThe WordPress.com Blog

WordPress.com is excited to announce our newest offering: a course just for beginning bloggers where you’ll learn everything you need to know about blogging from the most trusted experts in the industry. We have helped millions of blogs get up and running, we know what works, and we want you to to know everything we know. This course provides all the fundamental skills and inspiration you need to get your blog started, an interactive community forum, and content updated annually.

Simple way to integrate BPMN activiti with Spring Integration


BPMN 2 is an popular business process definition and execution standard. Alfresco Activiti is one of the most famous provider. Using BPMN shorten the distance between business and development perspective. It also enable the visibility of any complex business logic. Additionally, it also increase the portability of the business logic with the underline execution engine and therefore make the workflow application become enough flexible to adapt with the rapid change of the business demand.

Continue reading

Basic between websocket, stomp and sockjs with spring framework


We all understand that websocket is a full-duplex protocol that support bidirectional communication between client and server. However, during using this technology with spring framework, our first common issue is misconception websocket with stomp and sockjs together.

STOMP and SosckJS are different frameworks adding different features on top of websocket.

Continue reading

Spring JMS


Initialize project with ActiveQM Client

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-activemq</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>	

Enable JMS configuration

@Configuration
@EnableJms
public class IntegrationConfiguration {

}

Add integration layer controller

@Component
public class EmployeeJms {

    @Autowired
    private EmployeeService service;

    @JmsListener(destination = "employee-info-request")
    @SendTo("employee-info-response")
    public String getDepartment(String employeeId) {
        return service.getDepartment(employeeId);
    }
}

Simulation for business

@Service
public class EmployeeService {

    private static final Logger LOGGER = LoggerFactory
        .getLogger(EmployeeService.class);

    public String getDepartment(String employeeId) {
        LOGGER.info("Begin get department info of employee [{}]", employeeId);
        simulateQuery(employeeId, 3);
        LOGGER.info("End get department info of employee [{}]", employeeId);
        return "Technology";
    }

    private void simulateQuery(String employeeId, int processTime) {
        try {
            TimeUnit.SECONDS.sleep(processTime);
        }
        catch (InterruptedException e) {
        }
    }

}

Configure to point to Message Broker

spring:
    application:
        name: spring-jms
    profiles.active: default
    activemq:
        in-memory: false
        broker-url: tcp://activemq-dev:61616
        user: admin
        password: admin
    jms:
        listener:
            auto-startup: true
            concurrency: 3
            max-concurrency: 3

Spring Cloud Config Server pushes local changes


Create the Spring Cloud Config Server application

Add configuration

spring:
    application:
        name: config-server
    profiles:
        active: default
    cloud:
        config:
            retry:
                initialInterval: 100000
                multiplier: 1.1
                maxInterval: 900000
                maxAttempts: 6
            server:
                git:
                    uri: https://gitserver.org/configuration-repository.git
                    label: dev-local
                    search-paths: '*'
                    skipSslValidation: false
                    ignoreLocalSshSettings: true
                    strictHostKeyChecking: false
                    clone-on-start: true
                    force-pull: true
                    basedir: ${user.home}/data/configuration-repository
                    username: test_gitlab
                    password: ENC(07b8RBlZEtbdwVMjUBtlyeFPWBIfoVBl)

Add some extended functions for pushing changes

public class ConfigurationManagementServiceImpl
        implements ConfigurationManagementService {

    private static final Logger LOGGER = LoggerFactory
        .getLogger(ConfigurationManagementServiceImpl.class);

    private Git git = null;

    @Autowired
    private MultipleJGitEnvironmentRepository repository;

    @Override
    public void commitAndPush(
        final String application,
        final String profile,
        final String label,
        final String message) throws Exception {

        this.init();

        // Make the local repository ready
        this.repository.getLocations(application, profile, label);

        this.git.commit().setAll(true).setMessage(message).call();

        this.git.push()
            .setCredentialsProvider(this.repository.getGitCredentialsProvider())
            .call();

        LOGGER.info("Pushed local repository with message [{}].", message);
    }

    @SuppressWarnings("unused")
    private File getWorkingDirectory() {
        return this.repository.getBasedir();
    }

    private void init() throws IOException {
        if (this.git != null) {
            return;
        }

        final String repoPath = this.repository.getBasedir().getPath();
        final Repository localRepo = new FileRepository(repoPath + "/.git");
        this.git = new Git(localRepo);
        LOGGER.info("Initialized local repository at path {}", repoPath);
    }

    @SuppressWarnings("unused")
    private void updateLocalRepo() throws Exception {
        LOGGER.info("Updating the local repository.");
        this.init();
        this.git.pull()
            .setCredentialsProvider(this.repository.getGitCredentialsProvider())
            .call();
    }
}