-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #1409 Socket Mode: Slow message consumption when listeners do not…
… immediately return ack() (#1411)
- Loading branch information
Showing
4 changed files
with
296 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
bolt-jakarta-socket-mode/src/test/java/samples/ConcurrencyTestApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package samples; | ||
|
||
import com.slack.api.bolt.App; | ||
import com.slack.api.bolt.AppConfig; | ||
import com.slack.api.bolt.jakarta_socket_mode.SocketModeApp; | ||
import com.slack.api.model.event.MessageChangedEvent; | ||
import com.slack.api.model.event.MessageDeletedEvent; | ||
import com.slack.api.model.event.MessageEvent; | ||
import config.Constants; | ||
|
||
public class ConcurrencyTestApp { | ||
|
||
public static void main(String[] args) throws Exception { | ||
App app = new App(AppConfig.builder() | ||
.singleTeamBotToken(System.getenv(Constants.SLACK_SDK_TEST_SOCKET_MODE_BOT_TOKEN)) | ||
.build()); | ||
|
||
app.event(MessageEvent.class, (req, ctx) -> { | ||
// Without concurrency option, this time-consuming task slows the whole message processing mechanism down | ||
try { | ||
Thread.sleep(1000L); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
ctx.asyncClient().reactionsAdd(r -> r | ||
.channel(req.getEvent().getChannel()) | ||
.name("eyes") | ||
.timestamp(req.getEvent().getTs()) | ||
); | ||
return ctx.ack(); | ||
}); | ||
app.event(MessageChangedEvent.class, (req, ctx) -> ctx.ack()); | ||
app.event(MessageDeletedEvent.class, (req, ctx) -> ctx.ack()); | ||
|
||
String appToken = System.getenv(Constants.SLACK_SDK_TEST_SOCKET_MODE_APP_TOKEN); | ||
// SocketModeApp socketModeApp = new SocketModeApp(appToken, app); | ||
SocketModeApp socketModeApp = new SocketModeApp(appToken, app, 10); | ||
socketModeApp.start(); | ||
} | ||
} |
Oops, something went wrong.