How to get the biggest dump..!

Options
Aaron
Aaron Member, Administrator, Moderator, Employee Posts: 531 admin
edited October 2020 in Tips and Tricks #1

Message.dump() that is..!

One of the most convenient features in the Solace native APIs is the ability to just dump() out the contents of a message to the console for debugging. If you've ever used any of the basic Solace Samples, or used SdkPerf test tool, you have seen this output.

I wanted to find out: what is the largest dump() I could make?? Or, said another way: how many different header fields and elements could I use? So, using the JCSMP API, I tried to populate as many as I could. This is the result:

Destination:                            Topic 'test/direct'
SenderId:                               msg.setSenderId()
AppMessageType:                         msg.setApplicationMessageType()
AppMessageID:                           msg.setApplicationMessageId()
SequenceNumber:                         123456789
CorrelationId:                          msg.setCorrelationId()
SendTimestamp:                          1603692499396 (Mon Oct 26 2020 14:08:19.396)
Priority:                               254
Class Of Service:                       USER_COS_2
DeliveryMode:                           DIRECT
Message Id:                             5
Reply Message
ReplyTo:                                Topic '#P2P/v:sg-sol-3501-vmr/mPuoLl8m/Aarons-Thinkpad/31648/#000f0001/FAeiZoampP/msg.setReplyToSuffix()'
Deliver To One
TimeToLive:                             60000
DMQ Eligible
Eliding Eligible
User Data:                              len=17
  6d 73 67 2e 73 65 74 55    73 65 72 44 61 74 61 28    msg.setUserData(
  29                                                    )

User Property Map:                      2 entries
  Key 'an answer' (Integer): 42
  Key 'what is this' (String): user properties

HTTP Content Type:                      msg.setHTTPContentType
HTTP Content Encoding:                  msg.setHTTPContentEncoding()
Binary Attachment:                      len=23
  1c 17 54 65 78 74 20 4d    65 73 73 61 67 65 20 44    ..Text.Message.D
  69 72 65 63 74 21 00                                  irect!.

XML:                                    len=16
  6d 73 67 2e 77 72 69 74    65 42 79 74 65 73 28 29    msg.writeBytes()

That's a LOT of different things in the message. Did you know all of them? Leave a comment!

Full Java source code after the break.

Comments

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 531 admin
    edited October 2020 #2
    Options
    /*
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements.  See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership.  The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License.  You may obtain a copy of the License at
     *
     *   http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied.  See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    
    package com.solace.samples.others;
    
    import java.nio.charset.Charset;
    import java.util.concurrent.atomic.AtomicInteger;
    
    import com.solacesystems.jcsmp.BytesXMLMessage;
    import com.solacesystems.jcsmp.ConsumerFlowProperties;
    import com.solacesystems.jcsmp.DeliveryMode;
    import com.solacesystems.jcsmp.EndpointProperties;
    import com.solacesystems.jcsmp.FlowReceiver;
    import com.solacesystems.jcsmp.JCSMPException;
    import com.solacesystems.jcsmp.JCSMPFactory;
    import com.solacesystems.jcsmp.JCSMPProperties;
    import com.solacesystems.jcsmp.JCSMPSession;
    import com.solacesystems.jcsmp.JCSMPStreamingPublishEventHandler;
    import com.solacesystems.jcsmp.Queue;
    import com.solacesystems.jcsmp.SDTMap;
    import com.solacesystems.jcsmp.TextMessage;
    import com.solacesystems.jcsmp.User_Cos;
    import com.solacesystems.jcsmp.XMLMessageConsumer;
    import com.solacesystems.jcsmp.XMLMessageListener;
    import com.solacesystems.jcsmp.XMLMessageProducer;
    
    public class TestEveryMessageSetting {
    
        private static final Charset UTF_8 = Charset.forName("UTF-8");
        private static AtomicInteger directMessages = new AtomicInteger(0);
        private static AtomicInteger queueMessages = new AtomicInteger(0);
    
        public static void main(String... args) throws JCSMPException, InterruptedException {
    
            // Check command line arguments
            if (args.length < 3) {
                System.out.println("Usage: "+TestEveryMessageSetting.class.getSimpleName()+" <host:port> <message-vpn> <client-username> [client-password]");
                System.out.println();
                System.exit(-1);
            }
    
            System.out.println(TestEveryMessageSetting.class.getSimpleName()+" initializing...");
    
            // Create a JCSMP Session
            final JCSMPProperties properties = new JCSMPProperties();
            properties.setProperty(JCSMPProperties.HOST, args[0]);     // host:port
            properties.setProperty(JCSMPProperties.USERNAME, args[1]); // client-username
            properties.setProperty(JCSMPProperties.VPN_NAME,  args[2]); // message-vpn
            if (args.length > 3) { 
                properties.setProperty(JCSMPProperties.PASSWORD, args[3]); // client-password
            }
            // Make sure that the session is tolerant of the subscription already existing on the queue.
            properties.setProperty(JCSMPProperties.IGNORE_DUPLICATE_SUBSCRIPTION_ERROR, true);
    
            final JCSMPSession session =  JCSMPFactory.onlyInstance().createSession(properties);
    
            session.connect();
            System.out.println("Connected.");
    
            /** Anonymous inner-class for handling publishing events */
            XMLMessageProducer prod = session.getMessageProducer(new JCSMPStreamingPublishEventHandler() {
                @Override
                public void responseReceived(String messageID) {
                    System.out.println("******** Producer received response for msg: " + messageID);
                }
                @Override
                public void handleError(String messageID, JCSMPException e, long timestamp) {
                    System.out.printf("********* Producer received error for msg: %s@%s - %s%n",
                            messageID,timestamp,e);
                }
            });
    
            final XMLMessageConsumer cons = session.getMessageConsumer(new XMLMessageListener() {
                @Override
                public void onReceive(BytesXMLMessage msg) {
                    System.out.printf("========================%nDIRECT MESSAGE #%d RECEIVED:%n%s%n",directMessages.incrementAndGet(),msg.dump());
                }
    
                @Override
                public void onException(JCSMPException e) {
                    System.out.printf("******* Consumer received exception: %s%n",e);
                }
            });
            session.addSubscription(JCSMPFactory.onlyInstance().createTopic("test/>"));
            System.out.println("Connected. Awaiting message...");
            cons.start();
    
            // TEST1
            TextMessage msg = JCSMPFactory.onlyInstance().createMessage(TextMessage.class);
            msg.setText("Text Message Direct!");
            msg.setUserData("msg.setUserData()".getBytes(UTF_8));
            SDTMap map = JCSMPFactory.onlyInstance().createMap();
            map.putString("what is this","user properties");
            map.putInteger("an answer",42);
            msg.setProperties(map);
            msg.setAckImmediately(true);
            msg.setApplicationMessageId("msg.setApplicationMessageId()");
            msg.setApplicationMessageType("msg.setApplicationMessageType()");
            msg.setAsReplyMessage(true);
            msg.setCorrelationId("msg.setCorrelationId()");
            msg.setCorrelationKey(msg);
            msg.setCos(User_Cos.USER_COS_2);  // why not
            msg.setDeliverToOne(true);  // old school
            msg.setDeliveryMode(DeliveryMode.DIRECT);
            msg.setDMQEligible(true);
            msg.setElidingEligible(true);
            msg.setExpiration(System.currentTimeMillis()+(1000*60*60*24));
            msg.setHTTPContentEncoding("msg.setHTTPContentEncoding()");
            msg.setHTTPContentType("msg.setHTTPContentType");
            msg.setPriority(254);
            msg.setReplyTo(JCSMPFactory.onlyInstance().createTopic("msg.setReplyTo()"));
            //msg.setReplyToSuffix("msg.setReplyToSuffix()");  // overwrites previous reply-to with inbox topic
            msg.setSenderId("msg.setSenderId()");
            msg.setSenderTimestamp(System.currentTimeMillis());
            msg.setSequenceNumber(123456789);
            msg.setTimeToLive(1000*60);  // milliseconds
            //msg.writeAttachment("msg.writeAttachment()".getBytes(UTF_8));  // binary payload, overwrites TextMsg body
            msg.writeBytes("msg.writeBytes()".getBytes(UTF_8));  // XML payload, don't use this, just a test
            System.out.println("Sending FULL Direct Text Message");
            System.out.println(msg.dump());
            prod.send(msg,JCSMPFactory.onlyInstance().createTopic("test/direct"));
    
            Thread.sleep(1000);
            System.out.println("Exiting.");
            session.closeSession();
        }
    }