java httplistenerrequest_Spring Kafka Listener on Http Request

I am using Spring and Kafka, I make an HTTP POST request as shown below and send some info to another service via a Kafka topic.

@RequestMapping(method = RequestMethod.POST, value = "/portfolio")

public void getPortfolio(

Authentication auth,

@RequestBody User user

) {

//Data Transfer Object

UserDTO dto = user.toDTO();

dto.setId(((AuthenticatedUser) auth.getPrincipal()).getId());

//Sending message to Kafka topic

sender.sendPortfolioRequest(dto);

}

I then want to listen for the response on a different topic and return data in the HTTP response but am stuck here. I am able to listen to for the response using the below listener method but don't know how to put the two together.

@KafkaListener(

topics = Topics.PORTFOLIO_RESULT,

containerFactory = "portfolioKafkaListenerContainerFactory"

)

public void portfolioListener(UserPortfolioDTO portfolio) {

System.out.println("Recieved Portfolio: " + portfolio.toString());

}

P.S. I am new to using HTTP requests and don't know if this is the correct way to do what I'm trying to achieve or if I should be creating a new resource with the POST and redirecting to that or something else.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值