com.github.tyrion9:mtask-spring-boot-autoconfigure

Parent pom providing dependency and plugin management for applications built with Maven

License

License

Categories

Categories

Spring Boot Container Microservices Auto Application Layer Libs Code Generators config Configuration
GroupId

GroupId

com.github.tyrion9
ArtifactId

ArtifactId

mtask-spring-boot-autoconfigure
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Parent pom providing dependency and plugin management for applications built with Maven
Project URL

Project URL

https://projects.spring.io/spring-boot/#/spring-boot-starter-parent/mtask-spring-boot-autoconfigure

Download mtask-spring-boot-autoconfigure

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tyrion9/mtask-spring-boot-autoconfigure/ -->
<dependency>
    <groupId>com.github.tyrion9</groupId>
    <artifactId>mtask-spring-boot-autoconfigure</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.tyrion9/mtask-spring-boot-autoconfigure/
implementation 'com.github.tyrion9:mtask-spring-boot-autoconfigure:0.0.1'
// https://jarcasting.com/artifacts/com.github.tyrion9/mtask-spring-boot-autoconfigure/
implementation ("com.github.tyrion9:mtask-spring-boot-autoconfigure:0.0.1")
'com.github.tyrion9:mtask-spring-boot-autoconfigure:jar:0.0.1'
<dependency org="com.github.tyrion9" name="mtask-spring-boot-autoconfigure" rev="0.0.1">
  <artifact name="mtask-spring-boot-autoconfigure" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.tyrion9', module='mtask-spring-boot-autoconfigure', version='0.0.1')
)
libraryDependencies += "com.github.tyrion9" % "mtask-spring-boot-autoconfigure" % "0.0.1"
[com.github.tyrion9/mtask-spring-boot-autoconfigure "0.0.1"]

Dependencies

compile (8)

Group / Artifact Type Version
org.springframework.boot : spring-boot-autoconfigure jar 2.1.2.RELEASE
org.springframework.boot : spring-boot-configuration-processor jar 2.1.2.RELEASE
com.github.tyrion9 : mtask jar 0.0.1
org.springframework.boot : spring-boot-starter-web jar 2.1.2.RELEASE
org.springframework.boot : spring-boot-starter-jetty jar 2.1.2.RELEASE
org.springframework.boot : spring-boot-starter-websocket jar 2.1.2.RELEASE
org.apache.commons : commons-lang3 jar 3.8.1
org.yaml : snakeyaml jar 1.23

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.4

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.1.2.RELEASE

Project Modules

There are no modules declared in this project.

Managed Task (MTask)

Background task is required for every enterprise projects.

Spring Framework support many kind of background tasks: Spring Scheduling, Spring Boot Quartz...

MTask is based on Spring Boot add new feature for monitoring and controlling on the fly.

  • Add/remove Scheduling Task via Rest API (Spring Scheduling theo fixedrate hoặc cron)
  • Stop/start scheduling task via API (Restful API)
  • Change parameter's tasks via API (Restful API)
  • Monitoring task by realtime log via Websocket

Step by step

More info in mtask-sample

1. Import maven library:

        <dependency>
            <groupId>com.github.tyrion9</groupId>
            <artifactId>mtask-spring-boot-starter</artifactId>
            <version>0.0.1</version>
        </dependency>

2. Write a class extends MTask

HelloWorldMTask

public class HelloWorldMTask extends MTask {
    private static final Logger log = LoggerFactory.getLogger(HelloWorldMTask.class);

    @Override
    public void run() {
        log.info("Hello World"); 

        mlog.log("Hello World");  // Websocket Log
    }
}

ComplexMTask: declare parameters, autowired bean to use

public class ComplexMTask extends MTask {
    private static final Logger log = LoggerFactory.getLogger(ComplexMTask.class);

    @Autowired
    private GreetingService greetingService;

    @MTaskParam("name")
    private String name;

    @Override
    public void run() {
        String greetingMsg = greetingService.greeting(name);

        log.info(greetingMsg);
        mlog.log(greetingMsg); // websocket log
    }
}

3. declare mtask configuration (yaml)

-   code: helloworld
    scheduled:
        period: 1000
    name: Hello World MTask
    className: sample.sample1.HelloWorldMTask
    autoStart: true
-   code: complex
    scheduled:
        period: 1000
    name: Autowired Param MTask
    className: sample.sample2.ComplexMTask
    params:
        name: HoaiPN
    autoStart: true

4. Run

@SpringBootApplication
@ComponentScan(basePackages = {"com.github.tyrion9.mtask", "sample"})
public class SampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}

5. Monitor application

Client Tool is not developed yet, so use other tool for management:

  • Postman call rest API for management (stop/start/change parameters)
  • Simple Websocket Client - Chrome Plugin - to check log realtime

Real time log websocket-helloworld

websocket-complex

API list/stop/start/change parameters

curl -X GET http://localhost:8080/api

curl -X POST http://localhost:8080/api/helloworld/stop

curl -X POST http://localhost:8080/api/helloworld/start

rest-list

Versions

Version
0.0.1