Discover messagedriven mappedname, include the articles, news, trends, analysis and practical advice about messagedriven mappedname on alibabacloud.com
Through the first two articles"Advanced EJB" in-depth discussion of three kinds of bean (a)--session bean"Advanced EJB" to explore three kinds of Bean (ii)--entity BeanThe first two beans have been introduced, and today we continue to introduce the third type of bean--messagedriven bean.To say Messagedriven beans before you introduce the JMS (Java Message Service), JMS is the Java messaging Services, it is
specifies the JNDI name of the destination from which the beanwill consume messages. For complex message-driven beans, there can also be anactivationconfigElement containing @ activationconfigproperty annotations usedby the bean.
A message-drivenbean can also inject a messagedrivencontext resource. Commonly you use thisresource to call the setrollbackonly method to handle exceptions for a beanthat uses container-managed transactions.
Therefore, thefirst few lines of the simplemessagebean class
source code editor.Newmessage. Java. You can see that the class has the following annotations:
@MessageDriven(mappedName = "jms/Queue")
This annotation indicates to the container that the component is a message-driven bean and the bean uses JMS resources. The JMS resource is mapped to the JNDI name of the target, and the bean receives messages from the target.
The "New message-driven Bean" Wizard has cr
resource--External server 2 External Server Jnd Configuration Figure 3.3.5:jndi Parameters Create two destinations on external servers: Figure 3.3.6: Two goals and two connected factories: Figure 3.3.7: Two connection factories After the configuration, of course, to write an MDB test:The message-driven bean code is as follows:Java codePackageMqImportJavax.annotation.Resource;ImportJavax.ejb.ActivationConfigProperty;ImportJavax.ejb.MessageDriven;ImportJavax.jms.Message;ImportJavax.jms.MessageLis
beans . His business interface is javax.jms.MessageListener, which defines a single method:onMessage(). The following code shows a sample that shows a message-driven Bean (Used JMS the basic structure of the method). @MessageDriven (
mappedname= "DestinationQueue",
activationconfig = {
@ActivationConfigProperty ( Propertyname= "destinationtype",
propertyval
single method: onMessage ().
The following code example shows the basic structure of a message-driven bean (using the JMS method.
@MessageDriven( mappedName="destinationQueue", activationConfig = { @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="messageSelector",
. getstring ("name") ;}} finally {pstmt. close (); Conn. close ();}}}
The class dB is called directly here, which is not used in actual development. JPA is generally used. This is just an exercise.
So far, we have a basic interface, implementation class, that is, the implementation class that actually processes the business already exists, so there is currently no listener, that is to say, when listening to messages to trigger the actual service class, write a listener class. The main function o
servers have different differences.[3] Beanname: Specifies the name of the EJB (if @stateless or @stateful has not set the Name property, the default is the class name without the package name)[4] Mappedname: The jndi name of the EJB being injected, different servers have different differences.Example: through Beanname injection① local interface and implementation classes:Local interface public interface HelloWorld {public string SayHello (string nam
first time. in the next version of JBoss, @ EJB comments are from javax. the annotation package is moved to javax. EJB.
The following example demonstrates how to inject the hloworldbean stateless Session Bean stub to the injectionbean class. Java code
Injectionbean. Java
Package com. foshanshop. ejb3.impl;
Import com. foshanshop. ejb3.helloworld;
Import com. foshanshop. ejb3.injection;
Import javax. annotation. EJB;
Import javax. EJB. Remote;
Import javax. EJB. stateless;
@ Stateless
bean, the container calls the onmessage () method to pass the message as a parameter to the MDB. MDB decides how to process the message in onmessage. You can use annotations to specify which Destination Address (destination) The MDB listens ). When MDB is deployed, the container reads the configuration information.
Message-driven Bean ):
@ Messagedriven (activationconfig = {@ activationconfigproperty (propertyname = "destinationtype", propertyvalue =
an empty property value
});
What you need to illustrate here is the mapping parameter, which allows you to specify the matching rules between the attributes of the XML node and the properties of the JSON object, such as the properties of the Z:row node you want to Ows_title, the name in the JSON object is "Newtitle", Type is of type string, you can add such a mapping:[JavaScript]View Plaincopy
Ows_title: {mappedname: "Newtitle"
dependency injection of the EJB container automatically injects the corresponding EJB into the field or setter method.When using @ejb, you can specify the following properties:
Beaninterface: This property specifies the interface that is implemented by the injected EJB. This property is typically used to differentiate whether the referenced bean is a remote call bean or a local bean
Name: Used to specify the name of the registered key in the Jndi enc of the injected bean, which may
' Usercontroller ': Injection of resource dependencies failed; Nested exception is org.springframework.beans.factory.BeanCreationException:Error creating beans with Name ' UserService ': Injection of resource dependencies failed; Nested exception is Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [ Bz.sunlight.dao.UserDAO] found for dependency:expected at least 1 beans which qualifies as Autowire candidate for this DEP Endency. Dependency annotations:
interface ejbtestremote{public
string Gethello (string name); c5/>}Very simply, it simply declares an interface with a public Gethello (String name) abstract method inside the interface.
Let's take a look at the code inside the Ejbtest.java.
Package ejbtest;
Import Javax.ejb.Remote;
Import javax.ejb.Stateless;
/**
* Session Bean Implementation Class Ejbtest * *
@Stateless (mappedname= "Ejbname")
@Remote (Ejbtestremote.class)public class Ejb
(IDL)
Java message Service (JMS) API
Java Naming and Directory Interface (JNDI)
Java Remote method Invocation (RMI) and Object serialization
Java Servlet API
Java Transaction API (JTA)
Java Transaction Service (JTS)
JavaServer Pages (JSP) technology
JDBC Database Access API
In the specification of EJB 1.0, the correlation between components and Java naming and Directory Interface (JNDI), and the Java Transaction API (JTA) in programming to start and stop transactions, is made clear Rea
receive messages published after it subscribes. To receive messages, the subscriber must stay in the party state. Therefore, there is a time-dependent relationship between the publisher and the subscriber.
Point-to-Point message mode occurs after a queue. The producer of the message writes the message to the queue, and the subscriber of the message extracts the message from the queue. The publish-subscribe message mode goes through a hierarchical framework composed of a topic node. The message
In Spring AOP, there are 3 common concepts, advices, Pointcut, and Advisor, which are explained as follows:
Advices: Represents an action before or after a method is executed.
Pointcut: means to intercept a method based on the name of the method or the regular expression.
Advisor:advice and Pointcut are composed of separate units, and can be passed to the Proxy factory object.
We can use name matching and regular expression matching to match the method to intercept.1 Pointc
producer of a message writes a message to the queue, and the subscriber of the message extracts the message from the queue. The publish-subscribe message mode is implemented through a layered structure composed of a topic node. The message producer publishes messages to this hierarchy, and the subscriber of the message subscribes to the message.
The message-driven bean has only one bean class. In some respects, the JMS message-driven bean is similar to the stateless Session Bean: the message-d
onmessage. You can use annotations to specify which Destination Address (destination) The MDB listens ). When MDB is deployed, the container reads the configuration information.
Steps:
Create a message-driven Bean: messagedrivenbean implements messagelistener under CN. hqu. Message.
When the container detects that a message has arrived at the target address listened to by this JavaBean, it will help us obtain this message and send it to onmessage.
Annotations can be used to specify the type of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.