Skip to content

Commit bad0349

Browse files
authored
Merge pull request #9873 from stuartwdouglas/blocking-websockets
Allow websocket requests to run on a worker thread
2 parents bf97e2e + 0aec6b7 commit bad0349

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

extensions/undertow-websockets/deployment/src/main/java/io/quarkus/undertow/websockets/deployment/UndertowWebsocketProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public ServletContextAttributeBuildItem deploy(final CombinedIndexBuildItem inde
134134
new ReflectiveClassBuildItem(true, true, ClientEndpointConfig.Configurator.class.getName()));
135135

136136
return new ServletContextAttributeBuildItem(WebSocketDeploymentInfo.ATTRIBUTE_NAME,
137-
recorder.createDeploymentInfo(annotated, endpoints, config, websocketConfig.maxFrameSize));
137+
recorder.createDeploymentInfo(annotated, endpoints, config, websocketConfig.maxFrameSize,
138+
websocketConfig.dispatchToWorker));
138139
}
139140

140141
private void registerCodersForReflection(BuildProducer<ReflectiveClassBuildItem> reflection,

extensions/undertow-websockets/deployment/src/main/java/io/quarkus/undertow/websockets/deployment/WebsocketConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ public class WebsocketConfig {
99

1010
/**
1111
* The maximum amount of data that can be sent in a single frame.
12-
*
12+
*
1313
* Messages larger than this must be broken up into continuation frames.
1414
*/
1515
@ConfigItem(defaultValue = "65536")
1616
public int maxFrameSize;
17+
18+
/**
19+
* If the websocket methods should be run in a worker thread. This allows them to run
20+
* blocking tasks, however it will not be as fast as running directly in the IO thread.
21+
*/
22+
@ConfigItem(defaultValue = "false")
23+
public boolean dispatchToWorker;
1724
}

extensions/undertow-websockets/runtime/src/main/java/io/quarkus/undertow/websockets/runtime/UndertowWebsocketRecorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public void setupWorker(Executor executor) {
2424

2525
@SuppressWarnings("unchecked")
2626
public WebSocketDeploymentInfo createDeploymentInfo(Set<String> annotatedEndpoints, Set<String> endpoints,
27-
Set<String> serverApplicationConfigClasses, int maxFrameSize) {
27+
Set<String> serverApplicationConfigClasses, int maxFrameSize, boolean dispatchToWorker) {
2828
WebSocketDeploymentInfo container = new WebSocketDeploymentInfo();
2929
container.setMaxFrameSize(maxFrameSize);
30-
container.setDispatchToWorkerThread(false);
30+
container.setDispatchToWorkerThread(dispatchToWorker);
3131
container.setExecutor(new ExecutorSupplier());
3232
Set<Class<? extends Endpoint>> allScannedEndpointImplementations = new HashSet<>();
3333
for (String i : endpoints) {

0 commit comments

Comments
 (0)