欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

cometd后端直接publish消息给client

程序员文章站 2022-03-16 15:07:26
...

package testcomet
import org.cometd.client.*;
import org.eclipse.jetty.client.HttpClient;
class TestcometdService {

static transactional = true

def serviceMethod() {
HttpClient _httpClient;
_httpClient = new HttpClient();
_httpClient.setMaxConnectionsPerAddress(20000);
_httpClient.setIdleTimeout(15000);
_httpClient.start();
BayeuxClient client = new BayeuxClient(_httpClient, "http://localhost:8082/cometd");
client.start();

Map<String, Object> data = new HashMap<String, Object>();
// Fill in the data
data.msg="test msg";
client.publish("/chat/membersd", data, null);

}
}

相关标签: Eclipse