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:
/*
* 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();
}
}