306.6.2. 일괄 메시지 지원
SjmsProducer는 목록을 캡슐화하는 Exchange를 만들어 메시지 컬렉션을 게시할 수 있습니다.The SjmsProducer supports publishing a collection of messages by creating an Exchange that encapsulates a List
. 이 SjmsProducer는 목록 내용을 반복하고 각 메시지를 개별적으로 게시합니다.
메시지 배치를 생성할 때 각 메시지에 고유한 헤더를 설정해야 하는 경우 SJMS BatchMessage
클래스를 사용할 수 있습니다. SjmsProducer가 BatchMessage
목록에 표시되면 각 BatchMessage
를 반복하고 포함된 페이로드 및 헤더를 게시합니다.
다음은 BatchMessage 클래스를 사용하는 예입니다. 먼저 BatchMessage
목록을 만듭니다.
List<BatchMessage<String>> messages = new ArrayList<BatchMessage<String>>(); for (int i = 1; i <= messageCount; i++) { String body = "Hello World " + i; BatchMessage<String> message = new BatchMessage<String>(body, null); messages.add(message); }
그런 다음 목록을 게시합니다.
template.sendBody("sjms:queue:batch.queue", messages);