一个监听套接字请求的 EAR (Java EE) 应用程序 [英] an EAR (Java EE) application which listen to a socket request

查看:15
本文介绍了一个监听套接字请求的 EAR (Java EE) 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个 Java EE 应用程序(EAR),它不仅提供 Web 服务(WAR)或直接 JMS 请求(EJB),而且我还想接受套接字请求(例如 UDP 数据包).

I want to build a Java EE application (EAR) which not only provides web service(WAR) or direct JMS request (EJB), but I would like to also accept the socket request (e.g. UDP packet).

我尝试用 java.net.DatagramSocket 编写一个侦听器,让它作为单独的进程运行,并将请求重定向到我的 EAR 应用程序.

I have tried writing a listener with java.net.DatagramSocket, letting it run as separate process, and redirecting the request to my EAR application.

问题是..如何将此类套接字侦听器无缝构建到我的 Java EE (EAR) 应用程序中?

the question is.. how can I build such socket listener into my Java EE (EAR) applcation seamlessly?

谢谢.

推荐答案

正确 的方法是为此创建一个 JCA 适配器.JCA 适配器可用于出站入站连接.您可以在 JCA 适配器中启动线程或安排工作.从 JCA 适配器到 EJB 的入站连接是使用自定义消息驱动 bean 完成的.

The right approach would be to create a JCA adapter for that. JCA adapter can be used for outbound or inbound connectivity. You're allowed to start thread or schedule work in a JCA adpater. The inbound connectivity from the JCA adapter to the EJB is done using custom message-driven bean.

  • 适配器启动套接字侦听器并管理来自远程客户端的连接
  • 收到数据包后,会将消息传送到自定义 MDB
  • 然后 MDB 可以将处理委托给其他 EJB

您甚至可以从 JCA 连接器启动事务,以便处理消息/数据包到 EJB 的传递.JCA 是 Java EE 规范的一部分,所有应用服务器都支持.

You can even start transaction from the JCA connector so that the delivery of the message/packet to the EJB is transacted. JCA is part of the Java EE specifications and is supported by all application servers.

另一种方法(但不符合规范)是从 ServletContextListener 启动侦听套接字的线程.该线程将在 web 层中运行,您可以像往常一样调用 EJB.依赖注入不起作用,但 JNDI 查找应该还可以.

Another approach (but not compliant with the spec), is to start the thread that listens to the socket from a ServletContextListener. The thread will run in the web layer and you can call the EJB as usual. Dependency injection will not work, but JNDI lookup should still be ok.

这篇关于一个监听套接字请求的 EAR (Java EE) 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆