
org.jberet.support.io.JmsItemWriter Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2014 Red Hat, Inc. and/or its affiliates.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.jberet.support.io;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.jberet.support._private.SupportLogger;
import jakarta.batch.api.chunk.ItemWriter;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Named;
import jakarta.jms.JMSException;
import jakarta.jms.MapMessage;
import jakarta.jms.Message;
import jakarta.jms.MessageProducer;
/**
* An implementation of {@code jakarta.batch.api.chunk.ItemWriter} that sends data items to a JMS destination. It can
* sends the following JMS message types:
*
*
* - if the data item is of type {@code java.util.Map}, a {@code MapMessage} is created, populated with the data
* contained in the data item, and sent;
*
- else if the data item is of type {@code java.lang.String}, a {@code TextMessage} is created with the text content
* in the data item, and sent;
*
- else if the data is of type {@code jakarta.jms.Message}, it is sent as is;
*
- else an {@code ObjectMessage} is created with the data item object, and sent.
*
*
*
* @see JmsItemReader
* @see JmsItemReaderWriterBase
* @since 1.1.0
*/
@Named
@Dependent
public class JmsItemWriter extends JmsItemReaderWriterBase implements ItemWriter {
protected MessageProducer producer;
@Override
public void open(final Serializable checkpoint) throws Exception {
super.open(checkpoint);
producer = session.createProducer(destination);
}
@Override
public void writeItems(final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy