调试 okhttp-eventsource 连接日志

问题描述 投票:0回答:1

我正在编写一个玩具项目来接收维基媒体事件并将其传输到卡夫卡。我使用

okhttp-eventsource
连接到维基媒体。但我正在收到任何数据。我很难调试这个问题。

这是我的代码。服务器运行良好,但我没有看到来自维基媒体的事件。

 public void sendMessage() throws InterruptedException {
        String topic = "wikimedia_recent";
        BackgroundEventHandler backgroundEventHandler = new WikimediaChangesHandler(kafkaTemplate, topic);
        String url = "https://stream.wikimedia.org/v2/stream/recentchange";
        BackgroundEventSource.Builder builder = new BackgroundEventSource.Builder(backgroundEventHandler, new EventSource.Builder(URI.create(url)));
        try (BackgroundEventSource source = builder.build()) {
            source.start();
            System.out.println("source started");

        }
        TimeUnit.MINUTES.sleep(2);
    }

这是我想查看记录的处理程序方法:

@Override
    public void onMessage(String s, MessageEvent messageEvent) throws Exception {
        LOGGER.info(String.format("event data -> %s", messageEvent.getData()));
        kafkaTemplate.send(topic, messageEvent.getData());
    }

下面是我的日志,但我没有收到来自维基媒体的事件数据。有什么建议我如何进行调试吗?

2024-02-25T12:31:56.676-05:00 DEBUG 3654 --- [-stream[null]-1] okhttp3.internal.http2.Http2             : >> CONNECTION 505249202a20485454502f322e300d0a0d0a534d0d0a0d0a
2024-02-25T12:31:56.678-05:00 DEBUG 3654 --- [-stream[null]-1] okhttp3.internal.http2.Http2             : >> 0x00000000     6 SETTINGS      
2024-02-25T12:31:56.679-05:00 DEBUG 3654 --- [-stream[null]-1] okhttp3.internal.http2.Http2             : >> 0x00000000     4 WINDOW_UPDATE 
2024-02-25T12:31:56.680-05:00 DEBUG 3654 --- [-stream[null]-1] okhttp3.internal.concurrent.TaskRunner   : Q10005 scheduled after   0 µs: OkHttp stream.wikimedia.org
2024-02-25T12:31:56.681-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10005 starting              : OkHttp stream.wikimedia.org
2024-02-25T12:31:56.681-05:00 DEBUG 3654 --- [-stream[null]-1] okhttp3.internal.concurrent.TaskRunner   : Q10001 scheduled after   0 µs: OkHttp ConnectionPool
2024-02-25T12:31:56.681-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10001 starting              : OkHttp ConnectionPool
2024-02-25T12:31:56.681-05:00 DEBUG 3654 --- [ ConnectionPool] okhttp3.internal.concurrent.TaskRunner   : Q10001 run again after   1 s : OkHttp ConnectionPool
2024-02-25T12:31:56.682-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10001 finished run in 428 µs: OkHttp ConnectionPool
2024-02-25T12:31:56.693-05:00 DEBUG 3654 --- [-stream[null]-1] okhttp3.internal.http2.Http2             : >> 0x00000003    75 HEADERS       END_STREAM|END_HEADERS
2024-02-25T12:31:56.743-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000000    12 SETTINGS      
2024-02-25T12:31:56.745-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.concurrent.TaskRunner   : Q10002 scheduled after   0 µs: OkHttp stream.wikimedia.org applyAndAckSettings
2024-02-25T12:31:56.745-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10002 starting              : OkHttp stream.wikimedia.org applyAndAckSettings
2024-02-25T12:31:56.746-05:00 DEBUG 3654 --- [yAndAckSettings] okhttp3.internal.concurrent.TaskRunner   : Q10004 scheduled after   0 µs: OkHttp stream.wikimedia.org onSettings
2024-02-25T12:31:56.746-05:00 DEBUG 3654 --- [yAndAckSettings] okhttp3.internal.http2.Http2             : >> 0x00000000     0 SETTINGS      ACK
2024-02-25T12:31:56.746-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10004 starting              : OkHttp stream.wikimedia.org onSettings
2024-02-25T12:31:56.747-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10002 finished run in   1 ms: OkHttp stream.wikimedia.org applyAndAckSettings
2024-02-25T12:31:56.747-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10004 finished run in 165 µs: OkHttp stream.wikimedia.org onSettings
2024-02-25T12:31:56.791-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000000     0 SETTINGS      ACK
2024-02-25T12:31:56.946-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000003   797 HEADERS       END_HEADERS
2024-02-25T12:31:56.947-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000003     5 DATA          
2024-02-25T12:31:57.682-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10001 starting              : OkHttp ConnectionPool
2024-02-25T12:31:57.682-05:00 DEBUG 3654 --- [ ConnectionPool] okhttp3.internal.concurrent.TaskRunner   : Q10001 run again after   1 s : OkHttp ConnectionPool
2024-02-25T12:31:57.682-05:00 DEBUG 3654 --- [Http TaskRunner] okhttp3.internal.concurrent.TaskRunner   : Q10001 finished run in 397 µs: OkHttp ConnectionPool
2024-02-25T12:31:57.972-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000003    15 DATA          
2024-02-25T12:31:57.973-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000003   154 DATA          
2024-02-25T12:31:57.974-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000003  1287 DATA          
2024-02-25T12:31:57.974-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2             : << 0x00000003    15 DATA          
2024-02-25T12:31:57.975-05:00 DEBUG 3654 --- [m.wikimedia.org] okhttp3.internal.http2.Http2                 
java apache-kafka okhttp
1个回答
0
投票

TimeUnit.MINUTES.sleep(2);
移动到
try
块内:

public void sendMessage() throws InterruptedException {
    String topic = "wikimedia_recent";
    BackgroundEventHandler backgroundEventHandler = new WikimediaChangesHandler(kafkaTemplate, topic);
    String url = "https://stream.wikimedia.org/v2/stream/recentchange";
    BackgroundEventSource.Builder builder = new BackgroundEventSource.Builder(backgroundEventHandler, new EventSource.Builder(URI.create(url)));
    try (BackgroundEventSource source = builder.build()) {
        source.start();
        System.out.println("source started");
        TimeUnit.MINUTES.sleep(2);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.