-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueMessageProducer.java
More file actions
39 lines (33 loc) · 1.18 KB
/
QueueMessageProducer.java
File metadata and controls
39 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.javaee7.chapter10;
import javax.annotation.Resource;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.Queue;
/**
*
* @author Juneau
*/
@Named("queueMessageProducer")
public class QueueMessageProducer {
// Inject JMSContext if working within application server
// - Injection without any parameters utlizes the default application server
// connection factory
// @Inject
// JMSContext context myContext;
@Resource(name = "jms/acmeConnectionFactory")
private ConnectionFactory connectionFactory;
@Resource(lookup = "jms/Queue")
Queue inboundQueue;
public void sendMessage() {
JMSContext context = connectionFactory.createContext();
StringBuilder message = new StringBuilder();
message.append("Java EE 7 Is the Best!");
context.createProducer().send(inboundQueue, message.toString());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
FacesMessage.SEVERITY_INFO, "Message sent",
"Message sent"));
}
}