@Override public Receiptable acknowledge(StompHeaders headers, boolean consumed) { String receiptId = checkOrAddReceipt(headers); Receiptable receiptable = new ReceiptHandler(receiptId); StompCommand command = (consumed ? StompCommand.ACK : StompCommand.NACK); StompHeaderAccessor accessor = createHeaderAccessor(command); accessor.addNativeHeaders(headers); Message<byte[]> message = createMessage(accessor, null); execute(message); return receiptable; }
@Override public Receiptable send(String destination, Object payload) { StompHeaders headers = new StompHeaders(); headers.setDestination(destination); return send(headers, payload); }
@Override public Subscription subscribe(String destination, StompFrameHandler handler) { StompHeaders headers = new StompHeaders(); headers.setDestination(destination); return subscribe(headers, handler); }
@Override public final boolean match(Message<?> message) { StompHeaderAccessor headers = StompHeaderAccessor.wrap(message); if (!this.command.equals(headers.getCommand()) || (this.sessionId != headers.getSessionId())) { return false; } return matchInternal(headers, message.getPayload()); }
private StompHeaderAccessor createHeaderAccessor(StompCommand command) { StompHeaderAccessor accessor = StompHeaderAccessor.create(command); accessor.setSessionId(this.sessionId); accessor.setLeaveMutable(true); return accessor; }
@Override public String toString() { return "Subscription [id=" + getSubscriptionId() + ", destination='" + this.headers.getDestination() + "', receiptId='" + getReceiptId() + "', handler=" + getHandler() + "]"; } }
@Override public void disconnect() { this.closing = true; try { StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.DISCONNECT); Message<byte[]> message = createMessage(accessor, EMPTY_PAYLOAD); execute(message); } finally { resetConnection(); } }
private void checkBufferLimits() { Integer contentLength = this.expectedContentLength; if (contentLength != null && contentLength > this.bufferSizeLimit) { throw new StompConversionException( "STOMP 'content-length' header value " + this.expectedContentLength + " exceeds configured buffer size limit " + this.bufferSizeLimit); } if (getBufferSize() > this.bufferSizeLimit) { throw new StompConversionException("The configured STOMP buffer size limit of " + this.bufferSizeLimit + " bytes has been exceeded"); } }
/** * Invoked after the STOMP CONNECTED frame is received. At this point the * connection is ready for sending STOMP messages to the broker. */ protected void afterStompConnected(StompHeaderAccessor connectedHeaders) { this.isStompConnected = true; stats.incrementConnectedCount(); initHeartbeats(connectedHeaders); }
@Test public void brokerBecomingUnavailableTriggersErrorFrame() throws Exception { logger.debug("Starting test brokerBecomingUnavailableTriggersErrorFrame()"); String sess1 = "sess1"; MessageExchange connect = MessageExchangeBuilder.connect(sess1).build(); this.relay.handleMessage(connect.message); this.responseHandler.expectMessages(connect); MessageExchange error = MessageExchangeBuilder.error(sess1).build(); stopActiveMqBrokerAndAwait(); this.eventPublisher.expectBrokerAvailabilityEvent(false); this.responseHandler.expectMessages(error); }
/** * Connect and notify the given {@link StompSessionHandler} when connected * on the STOMP level. * @param handler the handler for the STOMP session * @return a ListenableFuture for access to the session when ready for use */ public ListenableFuture<StompSession> connect(StompSessionHandler handler) { return connect(null, handler); }
/** * Determine whether heartbeats are enabled. * <p>Returns {@code false} if {@link #setDefaultHeartbeat defaultHeartbeat} * is set to "0,0", and {@code true} otherwise. */ public boolean isDefaultHeartbeatEnabled() { long[] heartbeat = getDefaultHeartbeat(); return (heartbeat[0] != 0 && heartbeat[1] != 0); }
/** * Create headers for a heartbeat. While a STOMP heartbeat frame does not * have headers, a session id is needed for processing purposes at a minimum. */ public static StompHeaderAccessor createForHeartbeat() { return new StompHeaderAccessor(); }
@Override public void afterConnectionClosed() { super.afterConnectionClosed(); publishBrokerUnavailableEvent(); }
/** * Create an instance with the given host and port. * @param host the host * @param port the port */ public ReactorNettyTcpStompClient(String host, int port) { this.tcpClient = initTcpClient(host, port); }
@Override public String toString() { return super.toString() + ", subscriptionId=\"" + this.subscriptionId + "\", destination=\"" + this.destination + "\", payload=\"" + getPayloadAsText() + "\""; }
@Override protected void startInternal() { publishBrokerAvailableEvent(); // Force this, since we'll never actually connect super.startInternal(); } };
@Override public String toString() { return super.toString() + ", receiptId=\"" + this.receiptId + "\""; } }
@Override public Receiptable send(StompHeaders headers, Object payload) { Assert.hasText(headers.getDestination(), "Destination header is required"); String receiptId = checkOrAddReceipt(headers); Receiptable receiptable = new ReceiptHandler(receiptId); StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.SEND); accessor.addNativeHeaders(headers); Message<byte[]> message = createMessage(accessor, payload); execute(message); return receiptable; }
/** * Create an instance for the given STOMP command and headers. */ public static StompHeaderAccessor create(StompCommand command, Map<String, List<String>> headers) { return new StompHeaderAccessor(command, headers); }