HTTP Channel Adapter
The http-channel-adapter module implements an inbound HTTP server based on Undertow 2.2.x.
Dependency
<dependency>
<groupId>io.pipelite</groupId>
<artifactId>http-channel-adapter</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Usage as source (inbound)
Pipelite.defineFlow("http-inbound")
.fromSource("http://ingress") (1)
.process("handle", exchange -> {
String body = exchange.getInputPayloadAs(String.class);
exchange.setOutputPayload("OK");
})
.toSink("slf4j://log")
.build();
| 1 | Opens an HTTP listener on port 80 (default) at path /ingress. |
URL format
http://<path>
| Parameter | Default | Description |
|---|---|---|
path |
(required) |
The HTTP path on which the server listens (e.g. |
The Undertow server is started automatically by HttpChannelAdapter.onContextStarted() upon the first registration of an HTTP consumer.
| The default port is 80. Custom port and host configuration will be available in a future release. |
Usage as sink (outbound)
The module includes an HttpProducer for sending messages to external HTTP endpoints.
.toSink("http://target-service/api/notify")
The HttpProducer sends the payload as the body of an HTTP POST request.
Multiple path registration
Multiple paths can be registered on the same server:
context.registerFlowDefinition(
Pipelite.defineFlow("flow-orders")
.fromSource("http://orders").toSink("slf4j://orders").build()
);
context.registerFlowDefinition(
Pipelite.defineFlow("flow-payments")
.fromSource("http://payments").toSink("slf4j://payments").build()
);
HttpChannelAdapter maintains a per-path consumer map and shares a single Undertow instance.
Registering two flows on the same HTTP path is not allowed: IllegalStateException will be thrown.
|