@Override public void publish(K key, T event, long ttl) { this.publish( key, new BasicProperties.Builder().contentType("").deliveryMode(2).expiration(Long.toString(ttl)).build(), this.transcoder.encodeAsBytes(event) ); }
@Override public void publish(K key, T event) { this.publish( key, new BasicProperties.Builder().contentType("").deliveryMode(2).build(), this.transcoder.encodeAsBytes(event) ); }
@Override public void publish(T event, long ttl) { if (this.defaultKey == null) throw new QueueException("No default key is given, cannot publish, did you mean to use: publish(K key, T event)?"); this.publish( this.defaultKey, new BasicProperties.Builder().contentType("").deliveryMode(2).expiration(Long.toString(ttl)).build(), this.transcoder.encodeAsBytes(event) ); } }
@Override public void publish(T event) { if (this.defaultKey == null) throw new QueueException("No default key is given, cannot publish, did you mean to use: publish(K key, T event)?"); this.publish( this.defaultKey, new BasicProperties.Builder().contentType("").deliveryMode(2).build(), this.transcoder.encodeAsBytes(event) ); }
@Override public Future<R> publish(K key, long timeout, T event, Consumer<R> onSuccess, Consumer<Exception> onError) { try { PendingRequest future = new PendingRequest(event, onSuccess, onError); // store the pending request this.pendingRequests.put(future.getId(), future); // schedule the timeout this.timer.schedule(future, timeout); // publish the request this.channel.basicPublish( this.exchange.getName(), key == null ? "" : key.toString(), new BasicProperties("application/json", null, null, 1, null, future.getId(), this.replyQueue.getName(), null, null, null, null, null, null, null), this.transcoder.encodeAsBytes(event) ); return future; } catch (IOException e) { throw new QueueException("Failed to publish request", e); } }
protected void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { String correlationId = properties.getCorrelationId(); String replyTo = properties.getReplyTo(); if (correlationId != null && replyTo != null) { // decode the event T event = this.transcoder.decodeFromBytes(body); // handle the event R response = this.handler.handleDevliery(event); // ack the event this.channel.basicAck(envelope.getDeliveryTag(), false); // send the response if (response != null) { this.channel.basicPublish( "", replyTo, new BasicProperties("application/json", null, null, 1, null, correlationId, null, null, null, null, null, null, null, null), this.responseTranscoder.encodeAsBytes(response) ); } } else { logger.warn("Ignoring request without correlationId or replyTo"); } }