英文:
Websocket push notification to several JSF applications on Tomcat
问题
我有两个在Tomcat上运行的JSF应用程序。
- localhost:8080/app1/index.xhmtl
- localhost:8080/app2/index.xhmtl
在两个索引文件中,都在表单部分放置了相同的f:websocket标签。
<h:form>
...
...
...
<f:websocket channel="test" onmessage="socketListener" />
<h:outputScript>
function socketListener(message, channel, event) {
console.log(message);
}
</h:outputScript>
</h:form>
在两个托管bean中使用了相同的通道。
@ApplicationScoped
@Named
public class AppController implements Serializable
{
@Inject
@Push(channel = "test")
private PushContext pushContext;
public void sendMessage(String p_message)
{
pushContext.send(p_message);
}
...
...
...
}
但是,当我通过app1的JAVA方法pushContext.send
发送通知时,app2的JS方法socketListener
不起作用。
是否可能同时向多个JSF应用程序推送通知?
英文:
I have two JSF applications running on Tomcat.
- localhost:8080/app1/index.xhmtl
- localhost:8080/app2/index.xhmtl
In both index files the same f:websocket tag is placed in the form section.
<h:form>
...
...
...
<f:websocket channel="test" onmessage="socketListener" />
<h:outputScript>
function socketListener(message, channel, event) {
console.log(message);
}
</h:outputScript>
</h:form>
In both managed beans the same channel is used.
@ApplicationScoped
@Named
public class AppController implements Serializable
{
@Inject
@Push(channel = "test")
private PushContext pushContext;
public void sendMessage(String p_message)
{
pushContext.send(p_message);
}
...
...
...
}
But when I send a notification via JAVA method pushContext.send
of app1, the JS method socketListener
of app2 does not work.
Is it possible to push notification to several JSF applications at once?
答案1
得分: 3
Sure, here's the translated content:
网络套接字默认为应用程序范围。两个应用程序都有自己的应用程序范围。两个应用程序根本不共享相同的应用程序范围。你看,应用程序范围是一个范围,嗯,与单个应用程序关联。这是因为一个应用程序就是一个应用程序。啊好吧,我想你现在明白了
基本上,你想要跨应用程序通信。标准的Java EE API提供了JMS来实现这一点。但由于你正在使用一个裸骨的Tomcat Servlet容器,你的选择相当有限。你可以在Tomcat上安装JMS,但更好的方法是迁移到一个正常的Java EE服务器。Java EE版的Tomcat是TomEE。它已经预装了JSF、CDI、JMS等(基本上是Java EE的一切),无需通过WAR部署手动携带大量的JAR文件。
一旦在Tomcat中安装了JMS,或者迁移到了正常的Java EE服务器,那么你可以按照OmniFaces <o:socket>
文档中的“集群设计提示”部分的说明(<f:websocket>
的教父)进行操作。
英文:
The web socket is by default application scoped. Both applications have their own application scope. Both applications don't at all share the same application scope. You see, the application scope is a scope which is, well, tied to a single application. That's because one application is one application. Ah well, I think you get it now
You basically want cross-application communication. Standard Java EE API offers JMS for this out the box. But as you're using a barebones Tomcat servlet container, your options are pretty limited. You could install JMS on Tomcat, but better is to migrate to a normal Java EE server. The Java EE variant of Tomcat is TomEE. It already ships JSF, CDI, JMS and more out the box (basically, everything from Java EE), without the need to manually carry around a lot of JAR files via the WAR deployment.
Once having JMS installed in Tomcat, or migrated to a normal Java EE server, then you can follow the instructions in "Cluster design hints" section of the documentation of OmniFaces <o:socket>
(the godfather of the <f:websocket>
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论