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

2022-03-02 00:00:00 jmeter java groovy ibm-mq jms

我想了解为什么输出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:+.? '
" +
        "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'
"

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()),我可以看到整个文本消息。

以下是jeter控制台中的打印结果:

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.1inApacheJMeter.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 documentationcom.ibm.jms.JMSTextMessagecom.ibm.jms.JMSMessage继承toString()实现,the JavaDoc for that method表示:

获取包含邮件头的格式化版本的字符串。

我的猜测是,主体被截断只是因为toString()实际上只是为了给您提供标题。然而,只有IBM才会确切地知道它为什么会这样工作。需要说明的是,不能保证toString()将(或应该)返回整个邮件正文。

如果您确实希望检查文本消息的正文,则应该调用getText()。根据the JMS JavaDoc和IBM's own JavaDoc返回文本消息正文需要使用此方法。两种状态:

获取包含此消息数据的字符串。默认值为NULL。

相关文章