For this example we revert to the banking scenario. Now we will get a session bean to send a message to a JMS queue requesting that a new customer be added to the database. The message will be a Customer object with id, firstName
, and lastName
attributes. On receipt of the message, the MDB simply adds the customer to the database.
We have modified the BankServiceBean.addCustomer()
method so that it acts as a queue producer. The addCustomer()
method is invoked synchronously by a client in the usual manner. The code for addCustomer()
is shown below:
@Stateless
public class BankServiceBean implements BankService {
@Resource(mappedName="BankServiceConnectionFactory")
private ConnectionFactory cf;
@Resource(mappedName="BankServiceJMSQueue")
private Queue queue;
...
public void addCustomer(int custId, String firstName,
String lastName) {
try{
Customer cust = new Customer();
cust.setId(custId);
cust.setFirstName(firstName);
cust...