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); } }
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)); }
public void send(RouteSpec routeSpec, AMQP.BasicProperties properties, Object payload) throws IOException { send( routeSpec, "", properties, getBytes( MediaTypes.withCharset(properties.getContentType(), properties.getContentEncoding()), payload)); }