如何在Dropwizard中实现websocket

时间:2013-02-07 06:59:48

标签: websocket dropwizard

我需要使用dropwizard项目实现websocket。但是我无法找到任何与之相关的文件。任何人都可以指出相同的资源。

3 个答案:

答案 0 :(得分:7)

我一直在处理同样的问题,并认为我想分享我的解决方案: http://cvwjensen.wordpress.com/2014/08/02/websockets-in-dropwizard/

我使用Atmosphere框架,解决方案默认使用websockets,但如果需要,可以降级为长轮询。

这应该足以让你开始......

答案 1 :(得分:1)

我也希望这样做。这是迄今为止我发现的最佳信息:

据说最流行的websocket框架之一适用于Jersey(Jersey与Dropwizard捆绑在一起)。您可以在此处找到更多相关信息:https://github.com/Atmosphere/atmosphere

此外,有人发布了一个将两者合并在一起的存储库:https://github.com/mgutz/dropwizard-atmosphere/

答案 2 :(得分:1)

通过包含CometD,我将websockets实现到Dropwizard项目中。

CometD包含一个用于处理WS请求的servlet,Dropwizard公开了环境以允许您注册任意servlet。

我的应用程序(Groovy)的一小段摘录:

    environment.addServlet(new Initializer(httpClient, amqpConsumer), "/_initializer")
            .setInitOrder(2)

    environment.addServlet(AnnotationCometdServlet, "/cometd/*")
            .addInitParams([
            transports: 'org.cometd.websocket.server.WebSocketTransport',
            services: EventService.getCanonicalName(),
            jsonContext: 'org.cometd.server.JacksonJSONContextServer',
            maxSessionsPerBrowser: serviceConfiguration.maxBrowserSessions.toString(),
            maxInterval: '7200',
            logLevel: "2"
    ]).setInitOrder(1)

初始化servlet使事情变得简单,如CometD教程所示。