Closed victorgawk closed 7 months ago
Out of curiosity, what was null
?
The null
was a jakarta.jms.Destination
instance when creating a message producer in a JMS session. I pass null
because the producer in my application does not have a specified destination.
Code example:
import java.util.Hashtable;
import javax.naming.InitialContext;
import com.github.marschall.jakartajmsadapter.JakartaConnectionFactory;
import com.github.marschall.jakartajmsadapter.JakartaQueue;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
// ...
Hashtable<String, String> env = new Hashtable<>();
env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
env.put("java.naming.provider.url", "t3://host:port");
InitialContext ctx = new InitialContext(env);
ConnectionFactory connectionFactory = new JakartaConnectionFactory((javax.jms.ConnectionFactory)
ctx.lookup("connection factory JNDI"));
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(null); // <--- The error was happening here
// I choose the destination of the message only when I call the `send` method
Queue queue = new JakartaQueue((javax.jms.Queue) ctx.lookup("queue JNDI here"));
TextMessage message = session.createTextMessage("message here");
messageProducer.send(queue, message);
Wrapper should return null if object is null.