为什么 com.ibm.jms.JMSTextMessage 类型的变量会打印截断的内容和省略号 (...)?

Why does a variable of type com.ibm.jms.JMSTextMessage print truncated content and ellipses (...)?

我想了解为什么 com.ibm.jms.JMSTextMessage 类型的变量在转换为字符串时会打印出截断的内容和省略号 (...)。

我在 JMeter 的 JSR223 采样器中有这段代码:

import com.ibm.msg.client.jms.JmsConnectionFactory
import com.ibm.msg.client.jms.JmsFactoryFactory
import com.ibm.msg.client.wmq.WMQConstants
import javax.jms.Session
import javax.jms.TextMessage

def hostName = "127.0.0.1"
def hostPort = 1414
def channelName = "DEV.APP.SVRCONN"
def queueManagerName = "QM1"
def queueName = "DEV.QUEUE.1"

def ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER)
def cf = ff.createConnectionFactory()

cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, hostName)
cf.setIntProperty(WMQConstants.WMQ_PORT, hostPort)
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channelName)
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT)

def connInboundQueue = cf.createConnection("user", "password")

def sessInboundQueue = connInboundQueue.createSession(false, Session.AUTO_ACKNOWLEDGE)


def payload = "AAA:+.? '\n" +
        "ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'\n" +
        "DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'\n" +
        "GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'\n" +
        "JKL+745'\n" +
        "HHH+TN:IIAA891011213531235BNM422244:::001'\n" +
        "CCC+NT+++ABCDEFGHIJKLMNOPQRS'\n" +
        "STU+00123456789012:UF+0000000000:GY'\n" +
        "VXY+50+MI1234+++MI'\n" +
        "AAA+235+ABC'\n" +
        "BBB+200:3202062000:301'\n" +
        "FFF+90+USA'\n" +
        "BBB+232:2101051135:201'\n" +
        "CCC+FF+++AaBaBa001:TEST1'\n" +
        "DDD+3++G'\n" +
        "EEE+329:711013'\n" +
        "FFF+178+XXX'\n" +
        "FFF+179+YYY'\n" +
        "GGG+2+ZZZ'\n" +
        "HHH+BXG:ABCDEF'\n" +
        "HHH+ABC:12AB3E01234E8UD8'\n" +
        "III+P:110:111+100000001'\n" +
        "EEE+36:281105'\n" +
        "FFF+91+ASD'\n" +
        "VVV+50:2'\n" +
        "XXX+0011+1'\n" +
        "YYY+1+U0123456'\n" +
        "ZZZ+1+U1234560002'\n"

TextMessage msg = sessInboundQueue.createTextMessage()
msg.setText(payload)

log.info(msg.toString())
log.info(msg.getClass().toString())
log.info(msg.getText())

我想明白为什么log.info(msg.toString())不打印全部文本内容而在一些point (...)

之后显示省略号

如果我这样做 log.info(msg.getText()),我可以看到整个短信。

这是 jmeter 控制台中的打印结果:

2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue: 
  JMSMessage class: jms_text
  JMSType:          null
  JMSDeliveryMode:  2
  JMSDeliveryDelay: 0
  JMSDeliveryTime:  1635710725481
  JMSExpiration:    0
  JMSPriority:      4
  JMSMessageID:     ID:414d5120514d312020202020202020201f537d6101c31040
  JMSTimestamp:     1635710725481
  JMSCorrelationID: 1757416553
  JMSDestination:   queue:///DEV.QUEUE.1
  JMSReplyTo:       null
  JMSRedelivered:   false
    JMSXAppID: 4.1\bin\ApacheJMeter.jar    
    JMSXDeliveryCount: 0
    JMSXUserID: mquser1     
    JMS_IBM_PutApplType: 28
    JMS_IBM_PutDate: 20211031
    JMS_IBM_PutTime: 20052548
AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:20 ...
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue: class com.ibm.jms.JMSTextMessage
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue: AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'
GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'
JKL+745'
HHH+TN:IIAA891011213531235BNM422244:::001'
CCC+NT+++ABCDEFGHIJKLMNOPQRS'
STU+00123456789012:UF+0000000000:GY'
VXY+50+MI1234+++MI'
AAA+235+ABC'
BBB+200:3202062000:301'
FFF+90+USA'
BBB+232:2101051135:201'
CCC+FF+++AaBaBa001:TEST1'
DDD+3++G'
EEE+329:711013'
FFF+178+XXX'
FFF+179+YYY'
GGG+2+ZZZ'
HHH+BXG:ABCDEF'
HHH+ABC:12AB3E01234E8UD8'
III+P:110:111+100000001'
EEE+36:281105'
FFF+91+ASD'
VVV+50:2'
XXX+0011+1'
YYY+1+U0123456'
ZZZ+1+U1234560002'

IBM documentation com.ibm.jms.JMSTextMessage inherits the toString() implementation from com.ibm.jms.JMSMessage and the JavaDoc for that method说:

Gets a String containing a formatted version of the message header.

我的猜测是 body 被截断只是因为 toString() 实际上只是为了给你 header。但是,只有 IBM 才能确切知道它为何以这种方式工作。需要明确的是,不能保证 toString() 将(或应该)return 整个 body 消息。

如果您真的想检查短信的 body,您应该调用 getText()。这个方法需要根据the JMS JavaDoc as well as IBM's own JavaDocreturnbody的text-message。两个状态:

Gets the String containing this message's data. The default value is null.