cometd后端直接publish消息给client

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)