Skip to content

Commit

Permalink
NO-JIRA STOMP frame logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Jun 22, 2018
1 parent 4b13360 commit 72239ec
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@
import org.apache.activemq.artemis.utils.ConfigurationHelper;
import org.apache.activemq.artemis.utils.ExecutorFactory;
import org.apache.activemq.artemis.utils.VersionLoader;
import org.jboss.logging.Logger;

import static org.apache.activemq.artemis.core.protocol.stomp.ActiveMQStompProtocolMessageBundle.BUNDLE;

public final class StompConnection implements RemotingConnection {

private static final Logger logger = Logger.getLogger(StompConnection.class);

protected static final String CONNECTION_ID_PROP = "__AMQ_CID";
private static final String SERVER_NAME = "ActiveMQ-Artemis/" + VersionLoader.getVersion().getFullVersion() +
" ActiveMQ Artemis Messaging Engine";
Expand Down Expand Up @@ -582,6 +585,27 @@ public void handleFrame(StompFrame request) {
}
}

public void logFrame(StompFrame request, boolean in) {
if (logger.isDebugEnabled()) {
StringBuilder message = new StringBuilder()
.append("STOMP(")
.append(getRemoteAddress())
.append(", ")
.append(this.getID())
.append("):");

if (in) {
message.append(" IN << ");
} else {
message.append("OUT >> ");
}

message.append(request);

logger.debug(message.toString());
}
}

public void sendFrame(StompFrame frame, StompPostReceiptFunction function) {
manager.sendReply(this, frame, function);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ public int getEncodedSize() throws Exception {

@Override
public String toString() {
return "StompFrame[command=" + command + ", headers=" + headers + ", content= " + this.body + " bytes " +
Arrays.toString(bytesBody);
return new StringBuilder()
.append("StompFrame[command=").append(command)
.append(", headers=").append(headers)
.append(", content= ").append(this.body)
.append(", bytes= ").append(Arrays.toString(bytesBody))
.toString();
}

public boolean isPing() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void handleBuffer(final RemotingConnection connection, final ActiveMQBuff

try {
invokeInterceptors(this.incomingInterceptors, request, conn);
conn.logFrame(request, true);
conn.handleFrame(request);
} finally {
server.getStorageManager().clearContext();
Expand Down Expand Up @@ -186,11 +187,8 @@ public List<String> websocketSubprotocolIdentifiers() {
// Public --------------------------------------------------------

public boolean send(final StompConnection connection, final StompFrame frame) {
if (ActiveMQStompProtocolLogger.LOGGER.isTraceEnabled()) {
ActiveMQStompProtocolLogger.LOGGER.trace("sent " + frame);
}

invokeInterceptors(this.outgoingInterceptors, frame, connection);
connection.logFrame(frame, false);

synchronized (connection) {
if (connection.isDestroyed()) {
Expand Down
8 changes: 8 additions & 0 deletions docs/user-manual/en/stomp.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ In Apache ActiveMQ Artemis, these destinations are mapped to *addresses* and
*queues* depending on the operation being done and the desired semantics (e.g.
anycast or multicast).

## Logging

Incoming and outgoing STOMP frames can be logged by enabling `DEBUG` for
`org.apache.activemq.artemis.core.protocol.stomp.StompConnection`. This can be
extremely useful for debugging or simply monitoring client activity. Along with
the STOMP frame itself the remote IP address of the client is logged as well as
the internal connection ID so that frames from the same client can be correlated.

## Sending

When a STOMP client sends a message (using a `SEND` frame), the protocol
Expand Down

0 comments on commit 72239ec

Please sign in to comment.