Jersey Atmosphere Broadcast ไม่ได้ถูกส่งมอบ

ฉันยังใหม่กับ Atmosphere ดังนั้นฉันจึงขาดอะไรที่เรียบง่ายไป ฉันสร้างตัวอย่างและสามารถทำให้ @Broadcast ทำงานได้ แต่ไม่ใช่ BroadcasterFactory ที่จะทำงานได้ ฉันสามารถติดตาม onMessage ที่จะโดน (ผ่านผู้ฟัง) แต่ฉันไม่เห็น onBroadcast เกิดขึ้นเว้นแต่จะระบุ @Broadcast นอกจากนี้ เว้นแต่ฉันจะระบุ @Broadcast ฉันไม่เห็นข้อความที่ส่งถึงลูกค้า รหัส WebSocket ของฉันเป็นพื้นฐานมาก:

@Path("/chat")
@AtmosphereService(
        interceptors = {AtmosphereResourceLifecycleInterceptor.class, 
                        TrackMessageSizeInterceptor.class/*,
                        BroadcastOnPostAtmosphereInterceptor.class*/}//,
        )
public class HelloWorldWS {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public SuspendResponse<String> connect(@Context AtmosphereResource res) 
    {
        // eventually this will be done via subscription in the post area
        BroadcasterFactory.getDefault().get().addAtmosphereResource(res);

        return new SuspendResponse.SuspendResponseBuilder<String>()
                //.broadcaster(BroadcasterFactory.getDefault().get())
                .outputComments(true)
                .addListener(new ResourceListener())
                .build();
    }

    //@Broadcast(writeEntity = false)
    @POST
    public void broadcast(String message) {
        final String msg = String.format("{'author':'fdsa','message':'%s'}", "Override proof");
        // Send to all
        BroadcasterFactory.getDefault().get().broadcast(msg);
        // No Really, send to all
        Collection<Broadcaster> broadcasters = BroadcasterFactory.getDefault().lookupAll();
        for (Broadcaster b : broadcasters)
        {
            System.out.println("Broadcaster: " + b.toString() + "; Count: " + b.getAtmosphereResources().size());
            for (AtmosphereResource r : b.getAtmosphereResources())
            {
                System.out.println("Notifying Resource: " + r.toString());
                r.write(msg);
            }
        }
    }
}

เมื่อฉันเปิดใช้งาน @Broadcast/BroadcastOnPostAtmosphereInterceptor ข้อความจะถูกส่งต่อไปยังไคลเอนต์ (รหัสของฉันในฟังก์ชัน "broadcast" ไม่ได้ทำอะไรเลย) เมื่อฉันแสดงความคิดเห็น @Broadcast/BroadcastOnPostAtmosphereInterceptor ฉันคาดหวังว่ารหัส Broadcast ของฉันจะส่งข้อความ

ด้วย @Broadcast ฉันแสดงการเรียกกลับ ResourceListener ต่อไปนี้: onPreSuspend, onSuspend, onConnect, onMessage, onBroadcast (ลูกค้าได้รับ)

เมื่อ @Broadcast ถูกใส่ความคิดเห็น ฉันจะแสดงการเรียกกลับ ResourceListener ต่อไปนี้: onPreSuspend, onSuspend, onConnect, onMessage (ไคลเอนต์ไม่เคยได้รับข้อความ)

ผมทำอะไรผิดหรือเปล่า?

ฉันใช้บรรยากาศ 2.1.2 กับ Jersey 1.17


person BabelFish    schedule 09.04.2014    source แหล่งที่มา


คำตอบ (1)


กำจัด AtmosphereResourceLifecycleInterceptor คือคุณใช้ SuspendResponse API เนื่องจากอาจขัดแย้งกัน

person jfarcand    schedule 09.04.2014
comment
สิ่งนี้ดูเหมือนจะไม่ใช่ลิงก์ไปยังคำตอบ mustaccio แต่เป็นลิงก์ไปยังฟอรัมภายนอก ซึ่งแน่นอนว่าแย่กว่านั้นสำหรับ SO - person Tetsujin no Oni; 06.05.2014