Class ForwardingWebConsumer
java.lang.Object
io.fluxzero.sdk.web.ForwardingWebConsumer
- All Implemented Interfaces:
AutoCloseable
A specialized, opt-in {web request consumer that forwards incoming
Consider using
MessageType.WEBREQUEST messages to a locally running HTTP server.
This class is internally initialized when
FluxzeroBuilder.forwardWebRequestsToLocalServer(int) is
configured. Rather than routing messages through Fluxzero's internal handler infrastructure, it converts web requests
into raw HTTP requests and asynchronously sends them to http://localhost:port.
Purpose
This mechanism exists primarily for interoperability: it allows applications to integrate with their own HTTP servers (e.g., frameworks like Spring Boot, Jooby, or Vert.x) rather than adopting the Fluxzero message-based web handler framework.⚠️ Caution: Limited Use Case
While supported, use of this component is generally discouraged. It bypasses the core pull-based message consumption model of Fluxzero by pushing messages asynchronously to a local server. This introduces a risk of losing delivery guarantees, tracing consistency, and handler lifecycle control.Consider using
@HandleWeb-based handlers and declarative routing instead.
How It Works
- Consumes
WEBREQUESTmessages via aTracker - For each message, creates a corresponding
HttpRequestand sends it to localhost - Captures the
HttpResponseand converts it back into aSerializedMessage - Publishes the result using the
WEBRESPONSEGatewayClient
Features
- Header forwarding with filtering of restricted headers
- Support for request correlation and metadata propagation
- Graceful handling of 404s (configurable via
LocalServerConfig#isIgnore404()) - Fallback error response creation if the target server fails
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionForwardingWebConsumer(LocalServerConfig localServerConfig, ConsumerConfiguration configuration) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected HttpRequestprotected booleanisRestricted(String headerName) voidprotected SerializedMessageprotected SerializedMessagetoMessage(HttpResponse<byte[]> response, Map<String, String> correlationData)
-
Constructor Details
-
ForwardingWebConsumer
public ForwardingWebConsumer(LocalServerConfig localServerConfig, ConsumerConfiguration configuration)
-
-
Method Details
-
start
-
getCorrelationData
-
createRequest
-
isRestricted
-
toMessage
protected SerializedMessage toMessage(HttpResponse<byte[]> response, Map<String, String> correlationData) -
toMessage
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-