Skip to content

Commit

Permalink
[Issue 7049][WebSocket] Make WebSocketService.MaxTextFrameSize config…
Browse files Browse the repository at this point in the history
…urable (apache#7155)

Motivation
fix apache#7049
Make WebSocketService.MaxTextFrameSize configurable.

Modifications
Add config of webSocketMaxTextFrameSize in websocket.conf, standalone.conf, broker.conf, and the default value is 1024*1024byte.
  • Loading branch information
zhanghaou authored Jun 4, 2020
1 parent fb4a627 commit 32f528c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions conf/broker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@ webSocketConnectionsPerBroker=8
# Time in milliseconds that idle WebSocket session times out
webSocketSessionIdleTimeoutMillis=300000

# The maximum size of a text message during parsing in WebSocket proxy
webSocketMaxTextFrameSize=1048576

### --- Metrics --- ###

# Enable topic level metrics
Expand Down
3 changes: 3 additions & 0 deletions conf/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@ webSocketConnectionsPerBroker=8
# Time in milliseconds that idle WebSocket session times out
webSocketSessionIdleTimeoutMillis=300000

# The maximum size of a text message during parsing in WebSocket proxy
webSocketMaxTextFrameSize=1048576

### --- Metrics --- ###

# Enable topic level metrics
Expand Down
3 changes: 3 additions & 0 deletions conf/websocket.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ webSocketConnectionsPerBroker=8
# Time in milliseconds that idle WebSocket session times out
webSocketSessionIdleTimeoutMillis=300000

# The maximum size of a text message during parsing in WebSocket proxy
webSocketMaxTextFrameSize=1048576

### --- Authentication --- ###

# Enable authentication
Expand Down
2 changes: 2 additions & 0 deletions deployment/terraform-ansible/templates/broker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ webSocketNumIoThreads=8
# Number of connections per Broker in Pulsar Client used in WebSocket proxy
webSocketConnectionsPerBroker=8

# The maximum size of a text message during parsing in WebSocket proxy
webSocketMaxTextFrameSize=1048576

### --- Metrics --- ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,12 @@ public class ServiceConfiguration implements PulsarConfiguration {
)
private int webSocketSessionIdleTimeoutMillis = 300000;

@FieldContext(
category = CATEGORY_WEBSOCKET,
doc = "The maximum size of a text message during parsing in WebSocket proxy."
)
private int webSocketMaxTextFrameSize = 1048576;

/**** --- Metrics --- ****/
@FieldContext(
category = CATEGORY_METRICS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public WebSocketConsumerServlet(WebSocketService service) {

@Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setMaxTextMessageSize(WebSocketService.MaxTextFrameSize);
factory.getPolicy().setMaxTextMessageSize(service.getConfig().getWebSocketMaxTextFrameSize());
if (service.getConfig().getWebSocketSessionIdleTimeoutMillis() > 0) {
factory.getPolicy().setIdleTimeout(service.getConfig().getWebSocketSessionIdleTimeoutMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public WebSocketProducerServlet(WebSocketService service) {

@Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setMaxTextMessageSize(WebSocketService.MaxTextFrameSize);
factory.getPolicy().setMaxTextMessageSize(service.getConfig().getWebSocketMaxTextFrameSize());
if (service.getConfig().getWebSocketSessionIdleTimeoutMillis() > 0) {
factory.getPolicy().setIdleTimeout(service.getConfig().getWebSocketSessionIdleTimeoutMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public WebSocketReaderServlet(WebSocketService service) {

@Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setMaxTextMessageSize(WebSocketService.MaxTextFrameSize);
factory.getPolicy().setMaxTextMessageSize(service.getConfig().getWebSocketMaxTextFrameSize());
if (service.getConfig().getWebSocketSessionIdleTimeoutMillis() > 0) {
factory.getPolicy().setIdleTimeout(service.getConfig().getWebSocketSessionIdleTimeoutMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
*/
public class WebSocketService implements Closeable {

public static final int MaxTextFrameSize = 1024 * 1024;

AuthenticationService authenticationService;
AuthorizationService authorizationService;
PulsarClient pulsarClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class WebSocketProxyConfiguration implements PulsarConfiguration {
private Optional<Integer> webServicePortTls = Optional.empty();
// Hostname or IP address the service binds on, default is 0.0.0.0.
private String bindAddress;
// The maximum size of a text message during parsing in WebSocket proxy
private int webSocketMaxTextFrameSize = 1024 * 1024;
// --- Authentication ---
// Enable authentication
private boolean authenticationEnabled;
Expand Down Expand Up @@ -232,6 +234,14 @@ public void setBindAddress(String bindAddress) {
this.bindAddress = bindAddress;
}

public int getWebSocketMaxTextFrameSize() {
return webSocketMaxTextFrameSize;
}

public void setWebSocketMaxTextFrameSize(int webSocketMaxTextFrameSize) {
this.webSocketMaxTextFrameSize = webSocketMaxTextFrameSize;
}

public boolean isAuthenticationEnabled() {
return authenticationEnabled;
}
Expand Down

0 comments on commit 32f528c

Please sign in to comment.