generated from kestra-io/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dc3e5a
commit d6f5e95
Showing
9 changed files
with
410 additions
and
180 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
src/main/java/io/kestra/plugin/amqp/ConsumeBaseInterface.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.kestra.plugin.amqp; | ||
|
||
import io.kestra.core.models.annotations.PluginProperty; | ||
import io.kestra.plugin.amqp.models.SerdeType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public interface ConsumeBaseInterface { | ||
@NotNull | ||
@PluginProperty(dynamic = true) | ||
@Schema( | ||
title = "The queue to pull messages from." | ||
) | ||
String getQueue(); | ||
|
||
@PluginProperty(dynamic = true) | ||
@Schema( | ||
title = "A client-generated consumer tag to establish context." | ||
) | ||
@NotNull | ||
String getConsumerTag(); | ||
|
||
@NotNull | ||
SerdeType getSerdeType(); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.kestra.plugin.amqp; | ||
|
||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.models.conditions.ConditionContext; | ||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.triggers.*; | ||
import io.kestra.plugin.amqp.models.Message; | ||
import io.kestra.plugin.amqp.models.SerdeType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
import org.reactivestreams.Publisher; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.time.Duration; | ||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "React to and consume messages from an AMQP queue creating one executions for each message." | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
code = { | ||
"url: amqp://guest:guest@localhost:5672/my_vhost", | ||
"maxRecords: 2", | ||
"queue: amqpTrigger.queue" | ||
} | ||
) | ||
} | ||
) | ||
public class RealtimeTrigger extends AbstractTrigger implements RealtimeTriggerInterface, TriggerOutput<Message>, ConsumeBaseInterface, AmqpConnectionInterface { | ||
@Builder.Default | ||
private final Duration interval = Duration.ofSeconds(60); | ||
|
||
private String url; | ||
private String host; | ||
private String port; | ||
private String username; | ||
private String password; | ||
private String virtualHost; | ||
|
||
private String queue; | ||
|
||
@Builder.Default | ||
private String consumerTag = "Kestra"; | ||
|
||
private Integer maxRecords; | ||
|
||
private Duration maxDuration; | ||
|
||
@Builder.Default | ||
private SerdeType serdeType = SerdeType.STRING; | ||
|
||
@Override | ||
public Publisher<Execution> evaluate(ConditionContext conditionContext, TriggerContext context) throws Exception { | ||
Consume task = Consume.builder() | ||
.url(this.url) | ||
.host(this.host) | ||
.port(this.port) | ||
.username(this.username) | ||
.password(this.password) | ||
.virtualHost(this.virtualHost) | ||
.queue(this.queue) | ||
.consumerTag(this.consumerTag) | ||
.maxRecords(this.maxRecords) | ||
.maxDuration(this.maxDuration) | ||
.serdeType(this.serdeType) | ||
.build(); | ||
|
||
return Flux.from(task.stream(conditionContext.getRunContext())) | ||
.map((record) -> TriggerService.generateRealtimeExecution(this, context, record)); | ||
} | ||
} |
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
Oops, something went wrong.