Giter VIP home page Giter VIP logo

mover-process's Introduction

MOVER PROCESS

This dependency is designed for guaranteed processing of event queues in Spring applications. If you need to process a lot of events quickly, guaranteed not to lose any, even if your app crashes, then this is the solution for you.

Quick start Spring Boot

1. Add dependency

If we use Spring Boot 2 or Spring 5, then we can utilize the Mover Process starter package. Let's add the following dependency to the pom.xml file:

<dependency>
    <groupId>org.maxron.platform</groupId>
    <artifactId>mover-process</artifactId>
    <version>2.0.4</version>
</dependency>

2. Enable Mover Process

To enable Mover Process, Spring makes good use of annotations, much like enabling any other configuration level feature in the framework. We can enable the Mover Process feature simply by adding the @EnableMoverProcess annotation to any of the configuration classes:

@EnableMoverProcess
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Note: After we enable Mover Process, for the minimal setup, we must implement CommandExecutor.class and Command.class. CommandExecutor.class executes Command.class events in transaction

3. Implement Command or extend AbstractCommand

@Getter
public class YourExtendCommand extends AbstractCommand {
    private final YourDataEvent dataEvent;

    public YourExtendCommand(String commandId, String trackingKey, YourDataEvent dataEvent) {
        super(commandId, trackingKey);
        this.dataEvent = dataEvent;
    }
}

4. Implement CommandExecutor

@Component
public class YourCommandExecutor implements CommandExecutor<YourExtendCommand> {
    @Autowired
    private YourMessageChannel messageChannel;
    
    @Override
    public void executeInMoverTransaction(CommandExecution executionContext, TwCommand command) {
        try {
            if (messageChannel.send(command.getDataEvent())) {
                // the event was successful, remove it from the queue
                commandExecution.ok();
            } else {
                // re-executing the event
                commandExecution.retry();
            }
        } catch (Exception e) {
            if (isTransientException(e)) {
                // re-executing the event
                commandExecution.retry();
            } else {
                // stopping event processing to fix the error
                commandExecution.stop(e);
            }
        }
    }
}

mover-process's People

Contributors

maxronplatform avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.