Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Spring cloud stream functional bindings preview #828

Conversation

jsokolowskii
Copy link
Contributor

@jsokolowskii jsokolowskii commented Dec 5, 2022

This PR fixes Activiti/Activiti#4196 replacing the deprecated annotations from spring-cloud-stream with the new functional one provided by spring-cloud-function.

The annotation @StreamListener and @EnableBindings has been replaced with custom annotations defined in Activiti-Cloud#910:

  • @FunctionalBinding
  • @ConditionalFunctionalBinding
  • @ConnectorBinding

@jsokolowskii jsokolowskii force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch from 77d0da9 to 76347aa Compare December 5, 2022 11:18
@LorenzoDiGiuseppe LorenzoDiGiuseppe force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch 2 times, most recently from 0df5f5d to 2cf79a5 Compare December 20, 2022 11:25
@LorenzoDiGiuseppe LorenzoDiGiuseppe force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch from 14ef2b0 to 008aedd Compare December 22, 2022 14:24
@jsokolowskii jsokolowskii force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch from 012c0df to 2b11be4 Compare January 2, 2023 14:02
@LorenzoDiGiuseppe LorenzoDiGiuseppe marked this pull request as ready for review January 3, 2023 09:17
@LorenzoDiGiuseppe LorenzoDiGiuseppe changed the title [AAE-11278] Spring cloud stream functional bindings preview Spring cloud stream functional bindings preview Jan 3, 2023
@LorenzoDiGiuseppe LorenzoDiGiuseppe force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch from e6d5e44 to f91a867 Compare January 5, 2023 15:54
Copy link
Member

@erdemedeiros erdemedeiros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@LorenzoDiGiuseppe LorenzoDiGiuseppe force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch 2 times, most recently from 25f28de to d3ee169 Compare January 24, 2023 08:53
@jsokolowskii jsokolowskii force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch from 6baaf04 to a48f09d Compare January 25, 2023 14:30
@jsokolowskii jsokolowskii force-pushed the aae-11278-functional-bindings-dev-jsokolowski-ldigiuseppe-preview branch from a48f09d to 8d71a23 Compare January 25, 2023 15:24
Comment on lines +37 to +77
@Bean(INTERNAL_CHANNEL_PREFIX + ExampleConnectorChannels.EXAMPLE_CONNECTOR_CONSUMER)
@Override
public SubscribableChannel exampleConnectorConsumer() {
return MessageChannels.publishSubscribe(ExampleConnectorChannels.EXAMPLE_CONNECTOR_CONSUMER).get();
}

@Bean(INTERNAL_CHANNEL_PREFIX + HeadersConnectorChannels.HEADERS_CONNECTOR_CONSUMER)
@Override
public SubscribableChannel headersConnectorConsumer() {
return MessageChannels.publishSubscribe(HeadersConnectorChannels.HEADERS_CONNECTOR_CONSUMER).get();
}

@Bean(INTERNAL_CHANNEL_PREFIX + MoviesDescriptionConnectorChannels.MOVIES_DESCRIPTION_CONSUMER)
@Override
public SubscribableChannel moviesDescriptionConsumer() {
return MessageChannels.publishSubscribe(MoviesDescriptionConnectorChannels.MOVIES_DESCRIPTION_CONSUMER).get();
}

@Bean(INTERNAL_CHANNEL_PREFIX + MultiInstanceConnector.Channels.CHANNEL)
@Override
public SubscribableChannel miCloudConnectorInput() {
return MessageChannels.publishSubscribe(MultiInstanceConnector.Channels.CHANNEL).get();
}

@Bean(INTERNAL_CHANNEL_PREFIX + TestBpmnErrorConnector.Channels.CHANNEL)
@Override
public SubscribableChannel testBpmnErrorConnectorInput() {
return MessageChannels.publishSubscribe(TestBpmnErrorConnector.Channels.CHANNEL).get();
}

@Bean(INTERNAL_CHANNEL_PREFIX + TestErrorConnector.Channels.CHANNEL)
@Override
public SubscribableChannel testErrorConnectorInput() {
return MessageChannels.publishSubscribe(TestErrorConnector.Channels.CHANNEL).get();
}

@Bean(INTERNAL_CHANNEL_PREFIX + RestConnector.Channels.POST)
@Override
public SubscribableChannel restConnectorPost() {
return MessageChannels.publishSubscribe(RestConnector.Channels.POST).get();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's refactor this code using functional channel bindings.

@@ -56,7 +55,12 @@ public MultiInstanceConnector(
this.connectorProperties = connectorProperties;
}

@StreamListener(value = Channels.CHANNEL)
@Override
public Void apply(IntegrationRequest event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apply method can be implemented directly.

@@ -48,7 +46,12 @@ public RestConnector(IntegrationResultSender integrationResultSender, ConnectorP
this.connectorProperties = connectorProperties;
}

@StreamListener(Channels.POST)
@Override
public Void apply(IntegrationRequest event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apply method can be implemented directly.

SubscribableChannel testBpmnErrorConnectorInput();
}

@StreamListener(value = Channels.CHANNEL)
@Override
public Void apply(IntegrationRequest event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apply method can be implemented directly.

@StreamListener(value = Channels.CHANNEL)
public void handle(IntegrationRequest integrationRequest) throws InterruptedException {
@Override
public Void apply(IntegrationRequest event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apply method can be implemented directly.

Comment on lines +70 to +75
public Void apply(IntegrationRequest event) {
performTask(event);
return null;
}

public void performTask(IntegrationRequest event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apply method can be implemented directly or via separate Connector function bean that uses ExampleConnector consumer as a delegate.

@Component
@EnableBinding(ExampleConnectorChannels.class)
public class ExampleConnector {
@ConnectorBinding(input = ExampleConnectorChannels.EXAMPLE_CONNECTOR_CONSUMER, condition = "", outputHeader = "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to reset outputHeader attribute?

@jsokolowskii
Copy link
Contributor Author

The changes were merged in PR #875

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants