-2

I am pretty new to Spring Boot, and working on developing a mini application for myself, that will able to implement a service that provides a set of APIs for managing a set of calendars for different users. I am using STS IDE for this project and selected Apache Derby, JPA and Web dependencies for the same. I have created two Entity class for CalanderEvents and CalanderUser and the basic CRUD operation for both of them.

I have two questions:

1)I am using Postman app to implement CRUD operations and just cant figure out how to fetch Meeting time for Post master in STS so that I can create a background app that sends reminder 30 minutes prior to the meeting time. Will @Async work here?

2) For user based authentication, I think JWT will do the work, but do I need to have a GUI just to implement token based authentication, or can I do it through postman?

I am not sure if I am able to clearly put up my query, please let me know if you think I need to add some more information.

Thanks.

1 Answers1

1

Small precision -- you're not using Postman to implement CRUD; you're using Postman to test your implementation.

  1. @Async is used to allow the execution of methods in an asynchronous manner (in other words, multiple methods can run at the same time). What you're looking for is probably @Scheduled.

@Scheduled allows you to schedule a task every X amount of time -- in your case, to schedule the execution of a method, you'd do something like that:

@Scheduled(fixedRate = 1800000)
public void sendMessagePeriodically() {
    // ...
}

(1000ms * 60 * 30 = 1800000ms = 30min)

In order for the above to work, you can annotate a configuration class with @EnableScheduling:

@Configuration
@EnableScheduling
public class SchedulingConfiguration {

}

Alternatively, you can add @EnableScheduling on top of your main class (the one with @SpringBootApplication)

  1. No, you don't need a GUI. All you need to do is implement an authentication system either with Spring Security (which would make your work much easier), or by using a controller. Then, you can simply communicate with that API using Postman in order to authenticate yourself.

Good luck.


Update

For instance, you can schedule a task that runs every minute and checks if there's any events scheduled in 30 minutes. If there is, then send a notification:

@Scheduled(fixedRate = 60000)
public void checkForUpcomingEvents() {
    // get all events scheduled in ~30 minutes
    List<Event> events = getEventsScheduledSoon(); 
    for (Event event : events) { // for each event
        event.notifyUsers(); // notify all users concerned
    }
}

Note that it is important that you get all events that have an event in approximately 30 minutes (e.g. between 29 - 31), because while you can rely on @Scheduled to execute, you still need to consider potential delays. Following that logic, you also need to make sure that you don't notify the same person for the same event twice.

There are multiple variables to consider, for instance, how long does getting events take? How long does notifying the users take? Depending on those variables, you may need to adjust your configuration (e.g. run every 5 minutes instead of 1 minute).

There are really a lot of ways to go about this, your solution of using java's ExecutorService is also an excellent one, but as you have tagged your question with spring-boot and not java, I opted for the @Scheduled approach.

TwiN
  • 3,554
  • 1
  • 20
  • 31
  • As far as I understood from your response, the @Scheduled annotation will send notification every time after the scheduled intervals. What I am looking for is, a user get notification 30 mins prior to his/her meeting, that he scheduled from my API earlier. Do you think Java ExecutorService will be a better choice in this case? Sorry for not being too precise or including any code here, as I still need to figure out what exactly I need to implement. – Mili Sharma Jun 24 '18 at 21:20
  • @milisharma Updated my answer. – TwiN Jun 24 '18 at 22:22
  • I read about @Scheduled in detail and I guess this is the approach I would like to use now. Thanks. – Mili Sharma Jun 25 '18 at 02:10
  • @milisharma pleasure's mine. Make sure to mark this as an answer if it answered your question. Also, welcome to StackOverflow :) – TwiN Jun 25 '18 at 02:13
  • Yes, you saved my day today with your answers, and Thank you. I will try to contribute as much as I can, by answering users question in here. – Mili Sharma Jun 25 '18 at 04:15