JMS消息大小 [英] JMS message size

查看:247
本文介绍了JMS消息大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为使用JMS(即Spring框架JMS和Active MQ)在服务器和客户端之间发送带有有效负载的消息的应用程序开发带宽限制功能(不要问我为什么,这不是我的决定).

I'm currently working on bandwidth limiting feature (don't ask me why, its not my decision) for application which use JMS (Spring framework JMS and Active MQ namely) to sending messages with payload between server and clients.

我发现了许多限制输入JMS消息的节流方法(但都不基于实际的带宽负载),但是我没有找到任何限制输出消息流的方法.因此,我决定自己编写漏斗算法.

I found lot of throttling methods to limit incoming JMS messages (but none of them based on actual bandwidth load), however I didn't find any possible way to limit outgoing message flow. So I decided to write Leaky bucket algorithm on my own.

是否有某种方法可以获取JMS消息的大小?除了Java中的"sizeof"实现(

Is there some way how to obtain size of JMS message? Other than 'sizeof' implementation in Java (In Java, what is the best way to determine the size of an object?)

推荐答案

由于JMS消息在发送过程中被序列化,因此获取消息大小的最佳方法是

Because JMS messages are serialized in sending process, the best way how to obtain size of message is through ObjectOutputStream.

private int getMessageSizeInBytes(MessageWrapper message) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(message);
    oos.close();
    return baos.size();
}

这篇关于JMS消息大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆