This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.viveknaskar.smsalertsystem.domain.AlertMessage; | |
import com.viveknaskar.smsalertsystem.domain.User; | |
import com.viveknaskar.smsalertsystem.service.AlertService; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.PostMapping; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twilio.rest.api.v2010.account.Message; | |
import com.twilio.type.PhoneNumber; | |
import com.viveknaskar.smsalertsystem.domain.AlertMessage; | |
import com.viveknaskar.smsalertsystem.domain.User; | |
import com.viveknaskar.smsalertsystem.service.AlertService; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class AlertServiceImpl implements AlertService { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Twilio platform credentials | |
twilio.account.sid=<your-twilio-account-sid> | |
twilio.auth.token=<your-twilio-auth-token> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twilio.Twilio; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Configuration; | |
import javax.annotation.PostConstruct; | |
@Configuration | |
public class TwilioConfig { | |
@Value("${twilio.account.sid}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-test</artifactId> | |
<scope>test</scope> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
public class ExceptionallyExample { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
int val = 0; | |
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> { | |
if(val == 0) { | |
throw new IllegalArgumentException("Value is 0"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.TimeUnit; | |
public class ThenCombineExample { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> { | |
try { // delaying the thread by 2 seconds | |
TimeUnit.SECONDS.sleep(2); | |
} catch (InterruptedException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.TimeUnit; | |
public class ThenComposeExample { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> { | |
try { // delaying the thread by 2 seconds | |
TimeUnit.SECONDS.sleep(2); | |
} catch (InterruptedException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.TimeUnit; | |
public class ThenRunExample { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
CompletableFuture<Void> completableFuture = CompletableFuture.supplyAsync(() -> { | |
try { | |
// delaying the thread by 2 seconds | |
TimeUnit.SECONDS.sleep(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.TimeUnit; | |
public class ThenAcceptExample { | |
public static void main(String[] args) throws ExecutionException, InterruptedException { | |
CompletableFuture<Void> completableFuture = CompletableFuture.supplyAsync(() -> { | |
try { | |
// delaying the thread by 2 seconds | |
TimeUnit.SECONDS.sleep(2); |
NewerOlder