示例#1
0
文件: Qarrot.java 项目: viphe/qarrot
  public <T> T call(
      String queue, long timeout, MediaType mediaType, Object payload, Class<T> responseClass)
      throws IOException, TimeoutException, InterruptedException {
    String encoding = MediaTypes.getCharset(mediaType);

    byte[] body = getBytes(mediaType, payload);

    AMQP.BasicProperties.Builder bpb = new AMQP.BasicProperties.Builder();
    if (encoding != null) {
      bpb.contentEncoding(encoding);
    }

    RpcResponse response = call(queue, timeout, bpb.build(), body);

    MediaType responseMediaType = MediaType.valueOf(response.getProperties().getContentType());
    if (MediaTypes.isError(responseMediaType)) {
      RpcError rpcError;
      try {
        rpcError = fromBytes(responseMediaType, response.getBody(), RpcError.class);
      } catch (IllegalArgumentException e) {
        throw new IOException("unknown remote error");
      }

      if (rpcError == null) {
        throw new IOException("unknown remote error");
      } else {
        throw new IOException(rpcError.error + "\n" + rpcError.trace);
      }

    } else {
      return fromBytes(responseMediaType, response.getBody(), responseClass);
    }
  }
示例#2
0
文件: Qarrot.java 项目: viphe/qarrot
 public void send(
     RouteSpec routeSpec, String routingKey, AMQP.BasicProperties properties, Object payload)
     throws IOException {
   Route route = routeSpec.declareOn(channel, this);
   route.publishOn(
       channel, routingKey, properties, toBytes(MediaTypes.valueOf(properties), payload));
 }
示例#3
0
文件: Qarrot.java 项目: viphe/qarrot
 public void send(RouteSpec routeSpec, AMQP.BasicProperties properties, Object payload)
     throws IOException {
   send(
       routeSpec,
       "",
       properties,
       getBytes(
           MediaTypes.withCharset(properties.getContentType(), properties.getContentEncoding()),
           payload));
 }