powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / не могу "запустить" пример с MessageDrivenBean
1 сообщений из 1, страница 1 из 1
не могу "запустить" пример с MessageDrivenBean
    #38394176
kadet
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
пытаюсь научится работать с MDB, но не получается. Взял пример тут .
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
package ocpbcd.thema3;

import javax.ejb.ActivationConfigProperty;

@MessageDriven(name = "MessageMDBSample", activationConfig = {
		 @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		 @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/sampleQueue"),
		 @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
public class SendRecvClient implements MessageListener {

    public SendRecvClient() {
    }
    public void onMessage(Message message) {
        TextMessage tm = (TextMessage) message;
        try {
          System.out.println("Received message "+tm.getText());
        } catch (JMSException e) {
   
         e.printStackTrace();
        }
    }

}


обращаюсь к бину из сервлета:
Код: java
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.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
package ocpbcd.thema3;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/JMSClientServlet")
public class JMSClientServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String destinationName = "queue/sampleQueue";
		PrintWriter out = response.getWriter();
		Context ic = null;
		ConnectionFactory cf = null;
		Connection connection = null;

		try {
			ic = new InitialContext();

			cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
			Queue queue = (Queue) ic.lookup(destinationName);

			connection = cf.createConnection();
			Session session = connection.createSession(false,
					Session.AUTO_ACKNOWLEDGE);
			MessageProducer publisher = session.createProducer(queue);

			connection.start();

			TextMessage message = session.createTextMessage("Hello AS 7 !");
			publisher.send(message);

			out.println("Message sento to the JMS Provider");

		} catch (Exception exc) {
			exc.printStackTrace();
		} finally {

			if (connection != null) {
				try {
					connection.close();
				} catch (JMSException e) {
					e.printStackTrace();
				}
			}
		}
	}

}



в результате получаю ошибку:
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
21:01:15,267 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) javax.naming.NameNotFoundException: queue/sampleQueue -- service jboss.naming.context.java.queue.sampleQueue
21:01:15,269 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
21:01:15,270 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
21:01:15,271 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
21:01:15,271 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
21:01:15,272 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at javax.naming.InitialContext.lookup(InitialContext.java:411)
21:01:15,273 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at ocpbcd.thema3.JMSClientServlet.doGet(JMSClientServlet.java:39)
21:01:15,274 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
21:01:15,274 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
21:01:15,275 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
21:01:15,276 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
21:01:15,277 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
21:01:15,278 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
21:01:15,278 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
21:01:15,279 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
21:01:15,280 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
21:01:15,281 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
21:01:15,282 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
21:01:15,282 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
21:01:15,283 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
21:01:15,284 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
21:01:15,285 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) 	at java.lang.Thread.run(Thread.java:722)



однако эклипс в консоле мне показывал
Код: java
1.
2.
3.
4.
5.
6.
21:01:11,453 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 13) awaiting topic/queue creation jms/MyQueue
21:01:11,457 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 12) awaiting topic/queue creation queue/sampleQueue
21:01:13,455 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 13) Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@3ce9f destination=jms/MyQueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
21:01:13,458 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 12) Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@3ce9f destination=queue/sampleQueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
21:01:13,470 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 12) awaiting topic/queue creation queue/sampleQueue
21:01:13,470 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 13) awaiting topic/queue creation jms/MyQueue



пример пытаюсь выполнить на jboss-as-7.1.1.Final

в качестве файла конфигурации взял
Код: java
1.
standalone/configuration/standalone-full.xml 



я не понимаю что нужно делать,
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / не могу "запустить" пример с MessageDrivenBean
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]