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);
}
}