您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 02-JMS熟练应用.pdf
  所属分类: JavaME
  开发工具:
  文件大小: 716kb
  下载次数: 0
  上传时间: 2019-08-23
  提 供 者: qq_40******
 详细说明:activemq JMS PDF文档The main interfaces common to multiple APls are as follows Message, BytesMessage, MapMessage, ObjectMessage, Stream Message and TextMessage-a message sent to or received from a JMS provider. Queue-an administered object that encapsulates the identity of a message destination for point-to-point messaging Topic- an administered object that encapsulates the identity of a message destination for pub/sub messaging Destination -the common supertype of Queue and Topic 33 Classic Apl interfaces经典AP接囗【学会 The main interfaces provided by the classic aPl are as follows Connection Factory-an administered object used by a client to create a Connection. This interface is also used by the simplified API Connection-an active connection to a JMS provider Session-a single-threaded context for sending and receiving messages MessageProducer-an object created by a Session that is used for sending messages to a queue or topIC Message Consumer-an object created by a Session that is used for receiving messages sent to a queue or topic Connection Factory creates Connection creates Message session Message Producer creates creates Consumer sends to creates receives fr rom Destinati。n Message Destination 34 Simplified API interfaces简版APl接囗【了解】 The simplified API provides the same messaging functionality as the classic API but requires fewer interfaces and is simpler to use. The main interfaces provided by the simplified APl are as follows. Connection Factory -an administered object used by a client to create a Connection. This interface is also used by the classic aPI JMSContext-an active connection to a JMS provider and a singlethreaded context for sending and receiving messages JMSProducer-an object created by a JMS Context that is used for sending messages to a queue or topIc JMSConsumer-an object created by a JMSContext that is used for receiving messages sent to a queue or top Connect⊥on Factory creates JMSProducer JMSCon text JMSConsumer creates creates sends to creates receives trom Des七 ination Message Destination In the simplified API a single JMS Context object encompasses the behaviour which in the classic API is provided by two separate objects, a Connection and a Session. Although this specification refers to the JMS Context as having an underlying"connection"and"session, the simplified API does not use the Connection and session interfaces 3.5如何使用AP【掌握】 A typical JMS client using the classic APl executes the following JMS setup procedure Use JNDI to find a Connection Factory object Use JNDI to find one or more Destination objects Use the Connection Factory to create a JMS Connection object with message delivery inhibited Use the connection to create one or more Ms Session objects Use a session and the destinations to create the messageproducer and MessageConsumer objects needed Tell the Connection to start delivery of messages n contrast, a typical JMS client using the simplified API does the following:【了解】 Use JNDI to find a Connection Factory object Use JNDi to find one or more destination objects Use the Connection Factory to create a JMS Context object Use the MSContext to create the JMSProducer and MSConsumer objects needed Delivery of messages is started automatically At this point a client has the basic JMS setup needed to produce and consume messages 3.6多线程并发支持【了解】 classic APl JMS Object Supports Concurrent Use Destination YES Connection Factory YES Connection YES Session NO MessageProducer NO MessageConsumer NO simplified API JMS Object Supports Concurrent Use Destination YES Connection Factory YES JMSContext NO JMSProducer NO JMSConsumer NO 3.7掌握 Connection的AP 1.掌握 connection连接的 start、stop、cose方法的使用 2.了解 EXceptionListener 4消息发送 41同步发送 In the classic API the following methods on MessageProducer may be used to send a message synchronously send(Message message) send(Message message, int delivery Mode, int priority, long time ToLive send(Destination destination, Message message, int delivery Mode, int priority, long time Tolive send(Destination destination, Message message) These methods will block until the message has been sent. If necessary the call will block until a confirmation message has been received back from the JMS server. 42异步发送 421异步AP In the classic API the following methods on Message Producer may be used to send a message asynchronously send(Message message, CompletionListener completionListener send(Message message, int delivery Mode, int priority, long timeToLive, CompletionListener completionListener) send(Destination destination, Message message, CompletionListener completionListener send(Destination destination, Message message, int delivery Mode, int priority, long time ToLive, CompletionListener completionListener) 掌握 CompletionListener接口 public interface CompletionListener i 六六 Notifies the application that the mes sage has been success fu lly sent param message the message that was sent void incompletion (message message); Notifies user that the specified exception was thrown while attempting to *e send the specified message. If an exception occurs it is undefined w whether or not the message was successfully sent message e message that was sent ③ param exception the exception void onException (Message message, Exception exception) 422异步时消息的顺序:不需担心 Message order If the same producer is used to send multiple messages then JMS message ordering requirements( see section 6. 2.9"Message order)must be satisfied. This applies even if a combination of synchronous and asynchronous sends has been performed. The application is not required to wait for an asynchronous send to complete before sending the next message 4.2.3 Close commit or rollback A CompletionListener callback method must not call close on its own producer, session (including JMSContext)or connection or call commit or rollback on its own session. Doing so will cause the close, commit or rollback to throw an IllegalStateException or IllegalStateRuntime Exception (depending on the method signature) 424 ActiveMQ异步发送支持 https://activemg.apache.orglasync-sends 43发送有过期时间消息 A client can specify a time-to-live value in milliseconds for each message it sends. This is used to determine the message's expiration time which is calculated by adding the time-to-live value specified on the send method to the time the message was sent(for transacted sends, this is the time the client sends the message, not the time the transaction is committed) 44发送延时消息 A client can specify a delivery delay value in milliseconds for each message it sends. This is used to determine the message's delivery time which is calculated by adding the delivery delay value specified on the send method to the time the message was sent(for transacted sends, this is the time the client sends the message, not the time the transaction is committed) 45发送更优先的消息 priority 4.6设置消息的传递模式 JMS supports two modes of message delivery The non_ persistent mode is the lowest overhead delivery mode because it does not require that the message be logged to stable storage. A JMS provider failure can cause a NON PERSISTENT message to be lost The PErSiSTEnt mode instructs the JMs provider to take extra care to ensure the message is not lost in transit due to a JMS provider failure A JMS provider must deliver a NoN_PERSISTENT message at-most-once. This means it may lose the message, but it must not deliver it twice A JMS provider must deliver a PERSISTENT message once-and-only-once. This means a JMS provider failure must not cause it to be lost, and it must not deliver it twice PERSISTENT (once-and-only-once)and NON_PERSISTENT (at-most-once)message delivery are a way for a JMs client to select between delivery techniques that may lose a messages if a JMS provider dies and those which take extra effort to ensure that messages can survive such a failure. There is typically a performance/reliability trade-off implied by this choice. When a client selects the NoN_ PERSiStenT delivery mode, it is indicating that it values performance over reliability; a selection of PERSISTEnt reverses the requested trade-off. 4.7消息顺序 了解消息顺序。默认是时间先后顺序,明白哪些情况将对顺序产生影响。 Messages of higher priority may jump ahead of previous lower-priority messages Messages with a later delivery time may be delivered after messages with an earlier delivery time A client may not receive a NoN_ PERSISTENT message due to a JMS provider failure If both PERSISTENT and NON PERSISTENT messages are sent to a destination, order is only guaranteed within delivery mode. That is, a later NON_ PERSISTENT message may arrive thead of an earlier persistent message: however, it will never arrive ahead of an earlier NON_PERSISTENT message with the same priority A client may use a transacted session to group its sent messages into atomic units(the producer component of a JMS transaction). A transactions order of messages to a particular destination is significant the order of sent messages across destinations is not significant See section 6.2.tRansactions" for more information 5消息接收 5.1 Queue消息接收 掌握 Queue的 Consumer创建 52 Topic消息接收 掌握各种不同订阅方式 521非共享非持久化订阅 An unshared non-durable subscription is the simplest way to consume messages from a topic An unshared non-durable subscription is created, and a consumer object created on that subscription, using one of the following methods e In the classic aPl, one of several create consumer methods on session these return a MessageConsumer object In the simplified APL, one of several create Consumer methods on JMSContext These return d」 MSConsumer object Each unshared non-durable subscription has a single consumer. If the application needs to create multiple consumers on the same subscription then a shared non-durable subscription should be used instead The noLocal parameter may be used to specify that messages published to the topic by its own connection must not be added to the subscription 522非共享持久化订阅 a durable subscription is used by an application that needs to receive all the messages published on a topic, including the ones published when there is no consumer associated with it. The JMS provider retains a record of this durable subscription and ensures that all messages from the topic's publishers are retained until they are delivered to, and acknowledged by, a consumer on the durable subscription or until they have expired An unshared durable subscription may have only one active(i. e not closed)consumer at the same time An unshared durable subscription is created, and a consumer created on that subscription, using one of the following methods In the classic apl, one of several create Durable Consumer methods on session these return a Message Consumer object In the simplified APL, one of several createDurable Consumer methods on JMSContext These return a JMSConsumer object 必须指定订阅名 Messageconsumer createDurableconsumer (Topictopic, String name) throws JMSException; An unshared durable subscription is identified by a name specified by the client and by the client dentifier, which must be set. a client which subsequently wishes to create a consumer on that unshared durable subscription must use the same client identifier 取消持久订阅的方式: An unshared durable subscription is persisted and will continue to accumulate messages until it is deleted using the unsubscribe method on the session MSContext or Topicsession It is erroneous for a client to delete a durable subscription while it has an active consumer or while a message received from it is part of a current transaction or has not been acknowledged in the session void unsubscribe(String name) throws JMSEXception; 523共享非持久化订阅 A non-durable shared subscription is used by a client that needs to be able to share the work of receiving messages from a non-durable topic subscription amongst multiple consumers. A non durable shared subscription may therefore have more than one consumer. Each message from the subscription will be delivered to only one of the consumers on that subscription A shared non-durable subscription is created, and a consumer created on that subscription using one of the following methods In the classic APl, one of several create Shared Consumer methods on Session. These return a message consumer object In the simplified APl, one of several create Shared Consumer methods on JMSContext These return a JMSConsumer object. 必须指定订阅名(自定义) Messageconsumer createsharedConsumer(Topic topic, string sharedsubscriptionName) throws JMSException; 524共享持久化订阅 A durable subscription is used by an application that needs to receive all the messages published on a topic, including the ones published when there is no consumer associated with it. The JMS provider retains a record of this durable subscription and ensures that all messages from the topic's publishers are retained until they are delivered to, and acknowledged by, a consumer on the durable subscription or until they have expired a shared non-durable subscription is used by a client that needs to be able to share the work of receiving messages from a durable subscription amongst multiple consumers. A shared durable ubscription may therefore have more than one consumer. Each message from the subscription ill be delivered to only one of the consumers on that subscription A shared durable subscription is created, and a consumer created on that subscription, using one of the following methods: In the classic aPl one of several createshared Durableconsumer methods on session These return a message consumer object In the simplified APl, one of several create Shared Durable Consumer methods on JMSContext. These return a MSConsumer object MessageConsumer create sharedDurab l cOnsumer(Topic topic, String name) throws JMSEXception; 53同步方式接收消息 方法 说明 Message receive O; Returns the next message produced for this JMSConsumer Message receive Returns the next message produced for this JMS Consumer that (long timeout) arrives within the specified timeout period Message Returns the next message produced for this JMS Consumer if one is receive NoWait immediately available 54异步方式接收消息 A client can register an object that implements the MS MessageListener interface with a consumer As messages arrive for the consumer, the provider delivers them by calling the listener's on Message method. It is possible for a listener to throw a runtimeEXception; however, this is considered a client programming error. Well behaved listeners should catch such exceptions and attempt to divert messages causing them to some form of application-specific unprocessable message' destination
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 02-JMS熟练应用.pdf
 输入关键字,在本站1000多万海量源码库中尽情搜索: