Package io.fluxcapacitor.javaclient.web
Class ForwardingWebConsumer
java.lang.Object
io.fluxcapacitor.javaclient.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
FluxCapacitorBuilder.forwardWebRequestsToLocalServer(int)
is
configured. Rather than routing messages through Flux’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 Flux 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 Flux Capacitor 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
WEBREQUEST
messages via aTracker
- For each message, creates a corresponding
HttpRequest
and sends it to localhost - Captures the
HttpResponse
and converts it back into aSerializedMessage
- Publishes the result using the
WEBRESPONSE
GatewayClient
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 TypeMethodDescriptionvoid
close()
protected HttpRequest
protected boolean
isRestricted
(String headerName) void
start
(FluxCapacitor fluxCapacitor) protected SerializedMessage
protected SerializedMessage
toMessage
(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:
close
in interfaceAutoCloseable
-