spring-cloud / spring-cloud/spring-cloud-stream
Replacement for DirectProcessor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 646
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 8
Description
The issue is in reference to this question.
As per the comments provided, I tried to use StreamBridge to publish the events to the Kafka topic. Let me explain in detail by putting the code snippet before and after using Streambridge bean.
Before
- Supplier bean & its dependency to publish the events
@Autowired
private DirectProcessor<RequestDTO> source;
@Bean
public Supplier<Flux<RequestDTO>> supplier(){
return () -> Flux.from(source);
};
- Bean configuration class
@Bean
public DirectProcessor<RequestDTO> publisher(){
return DirectProcessor.create();
}
@Bean
public FluxSink<OrchestratorRequestDTO> sink(DirectProcessor<RequestDTO> publisher){
return publisher.sink();
}
- Class where this FluxSink bean is injected to publish the events.
@Autowired
private FluxSink<RequestDTO> sink;
public Order createOrder(RequestDTO requestDTO){
this.sink.next(this.getOrderRequestDTO(requestDTO));
// rest of the logic to return the response
}
After using StreamBridge
- & 2. In my opinion, these steps are not required. So, removed configuring the beans of type DirectProcessor & FluxSink
- A class where StreamBridge bean is now getting used. The binding name
supplier-out-0is configured in theapplication.yml
@Autowired
private StreamBridge bridge;
public Order createOrder(OrderRequestDTO orderRequestDTO){
this.bridge.send("supplier-out-0",
Flux.just(this.getOrderRequestDTO(requestDTO));
// rest of the logic to return the response
}
- This resulted in the below exception. Based on this exception, it looks like the
StreamBridgebean'ssend()method is expecting an object of typeMessage<T>.
java.lang.ClassCastException: class reactor.core.publisher.FluxMapFuseable cannot be cast to class org.springframework.messaging.Message (reactor.core.publisher.FluxMapFuseable and org.springframework.messaging.Message are in unnamed module of loader 'app')
at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:143) ~[spring-cloud-stream-3.0.6.RELEASE.jar:3.0.6.RELEASE]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP POST "/order/create" [ExceptionHandlingWebHandler]
Stack trace:
at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:143) ~[spring-cloud-stream-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:116) ~[spring-cloud-stream-3.0.6.RELEASE.jar:3.0.6.RELEASE]
The event published on this Kafka topic is processed by the processor mentioned below:
@Bean
public Function<Flux<RequestDTO>, Flux<ResponseDTO>> processor(){
return flux -> flux
.flatMap(dto -> this.orchestratorService.orderProduct(dto))
.doOnNext(...);
}
If the publisher starts using the StreamBridge then what are the expected changes in the processor() method mentioned above?
Additional details:
- Spring boot version- 2.3.12.RELEASE
- Spring cloud version- Hoxton.SR6
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the StreamBridge.send call, the supplier-out-0 binding in application.yml, and the processor() function shown in the issue. Read the relevant Spring Cloud Stream and StreamBridge behavior for the stated Spring Boot and Cloud versions; done means the replacement flow and required processor changes are established without the ClassCastException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kafka, spring, spring-boot
- Domain
- backend, stream-processing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100