我有一个流如下。我从http-api得到法语回复我看到很多时间差异。我正在使用一些消息转换器为utf-8。
如果来自http的回复是英文,我看到它在5分钟内处理法语20分钟。不确定http-client或json处理器是否花费时间或json创建需要时间。
file | xml-parser-processor | custom-http-client | json processor> queue
队列> HTTP客户端|处理器| >队列2
我的http客户端如下
</beans:bean>
<beans:bean id="batchRestTemplate" class="test.batch.httpclient.BatchRestTemplate" >
<beans:constructor-arg name="requestTimeOut" value="${requestTimeOut}"/>
<beans:constructor-arg name="maxConnectionPerRoute" value="${maxConnectionPerRoute}"/>
<beans:constructor-arg name="totalMaxConnections" ref="${totalMaxConnections}"/>
<int-http:outbound-gateway id='batch-http' header-mapper="headerMapper"
request-channel='toHttp'
rest-template="batchRestTemplate"
url-expression="payload.contains('${filterAttribute}') ? '${url1}' : '${url2}'" http-method="${httpMethod}"
expected-response-type='java.lang.String' charset='${charset}'
reply-timeout='${replyTimeout}' reply-channel='output'>
</int-http:outbound-gateway>
public BatchRestTemplate(Integer requestTimeOut,Integer totalMaxConnections,Integer maxConnectionPerRoute) throws NoSuchAlgorithmException {
super(createBatchHttpRequestFactory());
List<HttpMessageConverter<?>> messageConverters= new ArrayList<HttpMessageConverter<?>>();
messageConverters.addAll(getMessageConverters());
messageConverters.add(0,new StringHttpMessageConverter(Charset.forName("UTF-8")));
setMessageConverters(messageConverters);
}
我的处理器
JSONObject jsonData = new JSONObject(payload.getPayload());
byte[] msgCont = convertMsgContToBytes(jsonData);
String emailRequest = new JSONObject(
generateEMailRequest(payload, actualRecord))
.toString();
result = MessageBuilder.withPayload(emailRequest)
.copyHeaders(payload.getHeaders())
.setHeader(MESSAGE_TEXT, msgCont).build();
private byte[] convertMsgContToBytes(JSONObject jsonData)
throws EmailSMSProcessorException {
byte[] msgCont = null;
if (null != jsonData) {
try {
msgCont = jsonData.getJSONObject(MSG_CONTENT).toString()
.getBytes(UTF_8);
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error in converting Msg Content to Byte[]", e);
throw new EmailSMSProcessorException(e);
} catch (JSONException e) {
LOGGER.error("Error in converting Msg Content to Byte[]", e);
throw new EmailSMSProcessorException(e);
}
}
return msgCont;
}
private void validatePayload(Message<String> payload, String actualRecord)
throws EmailSMSProcessorException {
if (null != actualRecord) {
JSONObject jsonData = null;
try{
jsonData = new JSONObject(payload.getPayload());
}catch(Exception e){
throw new EmailSMSProcessorException(
"payload/mandatory data is missing",CONST_SYS_EXPTN);
}
validateErrorIdText(jsonData);
} else {
throw new EmailSMSProcessorException(
"payload/mandatory data is missing",CONST_SYS_EXPTN);
}
}
private EmailRequest generateEMailRequest(Message<String> payload,
String actualRecord) throws EmailSMSProcessorException {
EmailRequest emailReq = null;
if (null != actualRecord) {
JSONObject jsonPayload = new JSONObject(payload.getPayload());
JSONObject actualJSON = new JSONObject(actualRecord);
emailReq = new EmailRequest();
MessageRecipients messageRecipients = new MessageRecipients();
if (jsonPayload.has(MSG_CONTENT)) {
JSONObject msgCntJson = jsonPayload.getJSONObject(MSG_CONTENT);
if (msgCntJson.has(SUBSTI_CONTENT)) {
String substitutionContent = jsonPayload
.getJSONObject(MSG_CONTENT).get(SUBSTI_CONTENT)
.toString();
JSONObject substitutionContentJSONObj = new JSONObject(
substitutionContent);
messageRecipients.setSubstitutionKeyValueData(
substitutionContentJSONObj);
}
}
Recipient recipient = new Recipient();
recipient.setEmailAddress(isNullCheckMandatoryFields(
actualJSON.getString(CNTCT_PNT_ADR_TXT),
CNTCT_PNT_ADR_TXT));
messageRecipients.setRecipient(recipient);
MessageKeyValueData messageKeyValData = new MessageKeyValueData();
messageKeyValData.setAlertType(isNullCheckMandatoryFields(
actualJSON.getString(ALRT_TYPE_CD), ALRT_TYPE_CD));
messageKeyValData.setAlertTrackingId(isNullCheckMandatoryFields(
actualJSON.getString(DLVRY_ID), DLVRY_ID));
messageKeyValData.setIsDraft((getMessageProperties()!=null && getMessageProperties().getEnvironmentVar()!=null && !getMessageProperties().getEnvironmentVar().equalsIgnoreCase(ENVIORNMENT_PROD))?true:false);
messageRecipients.setMessageKeyValueData(messageKeyValData);
MessageEml message = new MessageEml();
String templId = actualJSON.getString(TMPL_ID);
String chnlType = actualJSON.getString(CHNL_TYPE);
String msgFormat = jsonPayload.getJSONObject(MSG_ATTRIBUTE)
.get(MSG_FORMAT).toString();
message.setTemplateId(
templId + UNDER_SCORE + chnlType + UNDER_SCORE + msgFormat);
message.setUseDraftTemplate((getMessageProperties()!=null && getMessageProperties().getEnvironmentVar()!=null && !getMessageProperties().getEnvironmentVar().equalsIgnoreCase(ENVIORNMENT_PROD))?true:false);
MessageRecipients[] messageRecipientsAry = new MessageRecipients[1];
messageRecipientsAry[0] = messageRecipients;
String substitutionKeyValueData = jsonPayload
.getJSONObject(MSG_CONTENT).get(TMPL_CONTENT).toString();
JSONObject substitutionKeyValueDataObj = new JSONObject(
substitutionKeyValueData);
emailReq.setMessageRecipients(messageRecipientsAry);
emailReq.setMessage(message);
emailReq.setSubstitutionKeyValueData(substitutionKeyValueDataObj);
}
return emailReq;
}
更新2:
这不是任何法语或英语。它在msg大小上,因为我的http-client子输出更大的有效载荷,这种情况发生。对于2 kb,如果msg大小为26 kb,它的快速速度为每分钟30k msg和每分钟2k msg。是因为血清化吗?下面是我构造json并作为字符串发送到输出通道的代码。我在标题消息头中再次传递响应也有来自http1响应的26kb相同
更新3 我正在通过我的http响应传递有效负载标题,这是26 kb。我现在删除它,我看到非常好的性能几乎与以前匹配。
我应该压缩我的标题并使用kyro + deflate zip发送吗?
CPU也很高