Java 大气:通过单个HttpConnection进行多个订阅

Java 大气:通过单个HttpConnection进行多个订阅,java,atmosphere,Java,Atmosphere,我在我的Spring MVC应用程序中使用Atmosphere来促进推送,使用流媒体传输 在我的应用程序的整个生命周期中,客户端将订阅和取消订阅许多不同的主题 Atmosphere似乎对每个订阅使用一个http连接,即对$.Atmosphere.subscribe(request)的每次调用都会创建一个新连接。这将很快耗尽允许从浏览器到大气服务器的连接数 我不希望每次都创建一个新的资源,而是希望能够在初始创建后向广播公司添加和删除AtmosphereResource 但是,由于Atmospher

我在我的Spring MVC应用程序中使用Atmosphere来促进推送,使用
流媒体
传输

在我的应用程序的整个生命周期中,客户端将订阅和取消订阅许多不同的主题

Atmosphere似乎对每个订阅使用一个http连接,即对
$.Atmosphere.subscribe(request)
的每次调用都会创建一个新连接。这将很快耗尽允许从浏览器到大气服务器的连接数

我不希望每次都创建一个新的资源,而是希望能够在初始创建后向广播公司添加和删除
AtmosphereResource

但是,由于
AtmosphereResource
是入站请求的一对一表示,因此每次客户端向服务器发送请求时,它都会到达一个新的
AtomsphereResource
,这意味着我无法引用原始资源,并将其附加到主题的
播音器中

我尝试对原始
subscribe()
调用返回的资源使用
$.atmospher.subscribe(request)
和调用
atmosphereResource.push(request)
。然而,这没有什么区别


正确的方法是什么?

以下是我如何让它工作的:

首先,当客户端进行初始连接时,在调用
suspend()
之前,确保浏览器接受特定于大气的标头:


我有完全相同的问题:客户端通过一个连接订阅多个广播电台,客户端可以随意添加和删除广播电台。不过,我在考试中没有考到你那么远。你对这件事有进一步的了解吗?这肯定是可能的吗?你试过邮件列表了吗?@Fletch Yep,成功了,多亏了IRC频道的一些人的指点。在下面发布了我的解决方案。“resource.getResponse().getHeader(ATMOSPHERE_TRACKING_ID)”似乎对我不起作用(可能是我的错)。我必须调用'atmosphereResource.uuid()'。您是如何获得
broadcasterFactory
变量的实例的?
@RequestMapping("/subscribe")
public ResponseEntity<HttpStatus> connect(AtmosphereResource resource)
{
    resource.getResponse().setHeader("Access-Control-Expose-Headers", ATMOSPHERE_TRACKING_ID + "," + X_CACHE_DATE);
    resource.suspend();
}
@RequestMapping(value="/subscribe", method=RequestMethod.POST)
public ResponseEntity<HttpStatus> addSubscription(AtmosphereResource resource, @RequestParam("topic") String topic)
{
    String atmosphereId = resource.getResponse().getHeader(ATMOSPHERE_TRACKING_ID);
    if (atmosphereId == null || atmosphereId.isEmpty())
    {
        log.error("Cannot add subscription, as the atmosphere tracking ID was not found");
        return new ResponseEntity<HttpStatus>(HttpStatus.BAD_REQUEST);
    }
    AtmosphereResource originalResource = resourceFactory.find(atmosphereId);
    if (originalResource == null)
    {
        log.error("The provided Atmosphere tracking ID is not associated to a known resource");
        return new ResponseEntity<HttpStatus>(HttpStatus.BAD_REQUEST);
    }

    Broadcaster broadcaster = broadcasterFactory.lookup(topic, true);
    broadcaster.addAtmosphereResource(originalResource);
    log.info("Added subscription to {} for atmosphere resource {}",topic, atmosphereId);

    return getOkResponse();
}