Kbase P46692: SonicMQ Adapter: How to publish a large message by splitting it into multiple messages?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  29/09/2004 |
|
Status: Unverified
GOAL:
How to split a large message into multiple smaller messages
GOAL:
Is there a way to split up a large message into smaller chunks?
FACT(s) (Environment):
SonicMQ
FIX:
This example code takes a sample file named sample.exe and puts it into a memptr. The memptr is then manipulated into smaller chunks. In the example the size of choice is 30 k. A bytesMessage is then created and the small chunks are published to the topic in multiple messages. This example code does not reassemble the chunks on the subscribing side.
DEFINE VARIABLE mBytesMessage AS MEMPTR NO-UNDO.
DEFINE VARIABLE pubsubsession AS HANDLE.
DEFINE VARIABLE messageH AS HANDLE.
DEFINE VAR vnum AS INTEGER.
RUN jms/pubsubsession.p PERSISTENT SET pubsubsession ("-H pccburns2k -S 5162 ").
RUN setBrokerURL IN pubsubsession ("pccburns2k:2507").
RUN SETUSER IN pubsubsession("Administrator").
RUN setpassword IN pubsubsession("Administrator").
RUN beginSession IN pubsubsession.
RUN loadFile2Memptr (INPUT "c:\temp\Sample.exe", OUTPUT mBytesMessage).
/* Stuff the large file into a mempointer */
PROCEDURE loadFile2Memptr:
DEFINE INPUT PARAMETER ipc_fileName AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER opm_message AS MEMPTR NO-UNDO.
FILE-INFO:FILE-NAME = ipc_fileName.
SET-SIZE(opm_message) = FILE-INFO:FILE-SIZE.
INPUT FROM VALUE(ipc_fileName) BINARY NO-MAP NO-CONVERT.
IMPORT UNFORMATTED opm_message.
INPUT CLOSE.
END PROCEDURE.
/* Process the data in the mempointer in smaller chunks */
DEFINE VARIABLE mChunk AS MEMPTR NO-UNDO.
DEFINE VARIABLE ipos AS INTEGER NO-UNDO.
DEFINE VARIABLE iChunk AS INTEGER NO-UNDO.
ASSIGN
ipos = 1
iChunk = 30000.
REPEAT WHILE ipos + iChunk < GET-SIZE(mBytesMessage):
SET-SIZE(mChunk) = 0.
mChunk = get-bytes (mBytesMessage, ipos, iChunk).
/*Process the current chunk */
RUN createBytesMessage IN pubsubsession (OUTPUT messageH).
/* attach memptr containing file to the message */
RUN setMemptr IN messageH(mChunk ,?,?).
RUN publish IN pubsubsession ("test", messageH, ?, ?, ?).
RUN deletemessage IN messageh.
ipos = ipos + iChunk.
END.
/*Process the last chunk here*/
RUN deletesession IN pubsubsession.