-
I have #32336 It seems that reactive is said to be a best practise of Quarkus while a lot of extensions become reactive. Can any one help on this, please?
LiveManager.java public static void onOpen(Long roomId, String userId, String name, Session session, Logger logger) {
Panache.withSession(() -> ensureRoom(roomId, userId, name, session, logger)).subscribe().with(liveUser -> {
loggedIn(roomId, session, liveUser, logger);
});
}
public static Uni<LiveUser> ensureRoom(Long roomId, String userId, String name, Session session, Logger logger) {
if (ROOM_MAP.containsKey(roomId)) {
LiveRoom liveRoom = ROOM_MAP.get(roomId);
return ensureUser(userId, name, session, liveRoom, logger);
} else {
return Room.<Room>findById(roomId).onItem().transformToUni(room -> {
if (room == null) {
return Uni.createFrom().nullItem();
} else {
LiveRoom liveRoom = new LiveRoom(logger, room);
ROOM_MAP.put(roomId, liveRoom);
return ensureUser(userId, name, session, liveRoom, logger);
}
});
}
} LiveServerEndpoint.java @OnOpen
public void onOpen(Session session, @PathParam("roomId") Long roomId) {
sharedLogger.getLogger().infof("onOpen: %s, %s", session, roomId);
String id, name;
if (securityIdentity.isAnonymous()) {
id = UUID.randomUUID().toString();
name = id;
} else {
id = jsonWebToken.getSubject();
name = jsonWebToken.getName();
}
LiveManager.onOpen(roomId, id, name, session, sharedLogger.getLogger());
} LiveResource.java @Path("/streams")
@POST
@WithSession
public Uni<LiveResponse> streams(JsonObject jsonObject) {
String app = jsonObject.getString("app");
String stream = jsonObject.getString("stream");
logger.info(jsonObject);
if (app.equals("live") && stream.equals("livestream")) {
return Uni.createFrom().item(new LiveResponse(LiveResponse.CODE_OK, "ok"));
} else {
String action = jsonObject.getString("action");
boolean publishing = action.equals("on_publish");
String param = jsonObject.getString("param");
param = param.replaceAll("\\?", "");
HashMap<String, String> paramMap = new HashMap<>();
for (String s : param.split("&")) {
String[] child = s.split("=");
paramMap.put(child[0], child[1]);
}
String streamCode = paramMap.get("streamCode");
try {
Long roomId = Long.parseLong(app);
return User.<User>findById(UUID.fromString(stream)).onItem().transformToUni(user -> {
if (user.streamCode.toString().equals(streamCode)) {
return LiveManager.ensureRoom(roomId, stream, user.name, null, sharedLogger.getLogger())
.onItem().transformToUni(liveUser -> onPublish(publishing, liveUser));
} else {
return Uni.createFrom().item(new LiveResponse(LiveResponse.CODE_STREAM_KEY_CHECK_FAILS, "code stream key check fails"));
}
});
} catch (NumberFormatException numberFormatException) {
return Uni.createFrom().item(new LiveResponse(LiveResponse.CODE_ROOM_ID_FORMAT_ERROR, "room id format error"));
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
/cc @DavideD (hibernate-reactive), @FroMage (panache,resteasy-reactive), @Sanne (hibernate-reactive), @Sgitario (resteasy-reactive), @gavinking (hibernate-reactive), @geoand (resteasy-reactive), @loicmathieu (panache), @stuartwdouglas (resteasy-reactive) |
Beta Was this translation helpful? Give feedback.
-
I found that the problem is caused by thread group changes. It sometimes use the executor-thread, sometimes use the vert.x-eventloop-thread. It's said that in RESTEasy Reactive: Everything runs on the event loop unless you add @Blocking to the endpoint. I have a OIDC authorizaiton settings. Does it matter? Why is it sometimes in the executor thread, sometimes in the eventloop thread? And I found this post here mentioned the authorization may affact this. |
Beta Was this translation helpful? Give feedback.
-
After a deep dive, I found tha it's caused by my code |
Beta Was this translation helpful? Give feedback.
-
Use emitOn to switch back to the original thread solve the problem.
|
Beta Was this translation helpful? Give feedback.
Use emitOn to switch back to the original thread solve the problem.