gpt4 book ai didi

rest - Atmosphere Jersey - 服务器消息

转载 作者:行者123 更新时间:2023-12-04 12:59:01 25 4
gpt4 key购买 nike

是否可以让服务器向所有连接的客户端发送消息而无需等待它们的任何操作?让我解释一下:-) 我一直在阅读 docs/examples我没有找到任何能满足我需求的东西:流程总是一样的;客户端连接(例如:对 Rest API 的 GET 调用),连接被暂停,直到收到新的 API 调用(例如:POST 调用),服务器才会等待(或者至少这是我所理解的)。我的用例非常不同:我希望服务器在新数据可用时发送一些“通知”。这将是我的用例(非常简化):

  • 客户端 A 连接到服务器
  • 由于目前没有新数据可用,连接已暂停
  • 服务器收到通知,新数据可从外部获得
    源并将其广播给客户端 A
  • 转到步骤 2

  • 到目前为止,我所取得的成就是成功建立了连接。下一步是解决这个服务器问题。我必须说这项技术对我来说是全新的,所以我可能误解了某些东西是如何工作的。如果是这样,请告诉我!

    这是我的堆栈:
  • Spring 3.2.0 发布
  • Jersey 1.8
  • Atmosphere Jersey 1.0.13
  • Tomcat 7.0.40

  • 谢谢大家!

    更新:关注后 this我收到这个警告,我不知道如何摆脱:
    2013-06-04 09:40:36,284 WARN [org.atmosphere.cpr.AtmosphereFramework] - Failed using comet support: org.atmosphere.container.Tomcat7AsyncSupportWithWebSocket, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.
    If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat.jar Is the Nio or Apr Connector enabled?
    2013-06-04 09:40:36,285 WARN [org.atmosphere.cpr.AtmosphereFramework] - Using org.atmosphere.container.Tomcat7BIOSupportWithWebSocket

    我按照应用程序结构评论 here ,所以这应该不是问题。我注意到通过将传输更改为“websocket”而不是“长轮询”显示没有错误。服务器最终发送数据艰难:)

    最佳答案

    我按照您的链接对代码进行了一些修改。

    当您在第 3 步“服务器收到来自外部源的通知新数据可用并将其广播到客户端 A”时,您必须像这样写一行:

    BroadcasterFactory.getDefault().lookup("/*").broadcast(response);

    起初我使用从我的 ActiveMQ 队列收到的 TextMessage 但我收到这个错误,所以我使用 Jackson 类作为对象响应,一切正常。

    SEVERE: A message body writer for Java class org.apache.activemq.command.ActiveMQTextMessage, and Java type class org.apache.activemq.command.ActiveMQTextMessage, and MIME media type application/json was not found jun 03, 2014 11:32:21 AM com.sun.jersey.spi.container.ContainerResponse write SEVERE: The registered message body writers compatible with the MIME media type are: application/json (JSONJAXBElementProvider, JSONArrayProvider, JSONObjectProvider, JSONRootElementProvider, JSONListElementProvider, ...)

    关于rest - Atmosphere Jersey - 服务器消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16906474/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com