Skip to content

Instantly share code, notes, and snippets.

View chathurangat's full-sized avatar

Chathuranga Tennakoon chathurangat

View GitHub Profile
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.springbootdev.amazon.s3.example.aws.service.AmazonS3ClientService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
public interface AmazonS3ClientService
{
void uploadFileToS3Bucket(MultipartFile multipartFile, boolean enablePublicReadAccess);
void deleteFileFromS3Bucket(String fileName);
}
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
@Slf4j
@EnableBinding(OrderSink.class)
public class OrderListener
{
@StreamListener(target = OrderSink.INPUT,condition = "headers['payment_mode']=='cash'")
public void listenForCashOrder(Order order)
{
log.info(" received new CASH order {} ",order.toString());
}
@Slf4j
@EnableBinding(OrderSource.class)
@RestController
public class OrderController
{
@Autowired
private OrderSource source;
@PostMapping("/orders/publish")
public String publishOrder(@RequestBody Order order, @RequestParam("payment_mode") String paymentMode)
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
@Slf4j
@EnableBinding(OrderSink.class)
public class OrderListener
{
@StreamListener(target = OrderSink.INPUT)
public void listenForOrder(Order order)
import org.springframework.cloud.stream.annotation.Input;
import org.springframework.messaging.SubscribableChannel;
public interface OrderSink
{
String INPUT = "orderReceiveChannel";
@Input(INPUT)
SubscribableChannel receive();
}
@Slf4j
@EnableBinding(OrderSource.class)
@RestController
public class OrderController
{
@Autowired
private OrderSource source;
@PostMapping("/orders/publish")
public String publishOrder(@RequestBody Order order)
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel;
public interface OrderSource
{
String OUTPUT = "orderPublishChannel";
@Output(OUTPUT)
MessageChannel create();
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
@EnableBinding(Sink.class)
public class OrderListener
{
private static final Logger logger = LoggerFactory.getLogger(OrderListener.class);