Because the project needs some data to be pushed and received, because the amount of data is relatively large, about 3 million data a day
At the beginning, I used http post to submit data, but found that it was too slow, and the sending speed was much smaller than the receiving speed.
Therefore, if you want to use a long socket connection to push and receive data, write the socket server and client yourself, one is a waste of time, but it may not be done well
Finally, activemq is used to push and receive data
First, the producer code is as follows:
Consumer, there are two models:
1: Ordinary subscription, no need for persistent "subscription", that is, when connecting, you can receive messages, and you can't receive messages before connecting, using "CreateConsumer" 2: Persistent subscription, after connecting, you can receive data that has not been pushed before, using "CreateDurableConsumer"
Links to the introduction of CreateDurableConsumer:The hyperlink login is visible.
Create a non-shared persistent subscription on the specified topic if it doesn't already exist, and create a consumer on that persistent subscription. This method creates a persistent subscription without using a message selector, and the noLocal value is false. The application uses a persistent subscription, and the application needs to receive all messages published on the topic, including messages published when there are no active consumers associated with it. The JMS provider keeps a record of this persistent subscription and ensures that all messages from the subject publisher will be retained until they are delivered to the consumer and confirmed by that persistent subscription until they have expired.
Persistent subscriptions continue to accumulate messages until they are deleted using the unsubscribe method.
This method can only be used with non-shared persistent subscriptions. Any persistent subscriptions created using this method will be unshared. This means that only one active (i.e., not closed) consumer can exist on the subscription at a time. The term "consumer" here denotes the TopicSubscriber, MessageConsumer, or JMSConsumer object in any client.
A non-shared persistent subscription is identified by a client-specified name and a client identifier that must be set. Applications that then want to create consumers on a non-shared persistent subscription must use the same client identifier.
If an unshared persistent subscription with the same name and client identifier already exists, and the same topic, message selector, and noLocal value are already specified, and no consumer is already active (i.e., not closed) on the persistent subscription, this method creates an existing durable subscription on the MessageConsumer.
If a non-shared persistent subscription with the same name and client identifier already exists, and there is a consumer on the persistent subscription that is already active (i.e., not closed), a JMSException will be thrown.
If there is already a non-shared persistent subscription with the same name and client identifier but a different subject, a message selector or noLocal value has been specified, and no consumer is already active (i.e. not closed) on the persistent subscription, then this is equivalent to unsubscribing (deleting) the old one and creating a new one.
Shared and non-shared persistent subscriptions may not have the same name and client identity. If a shared persistent subscription with the same name and client identifier already exists, a JMSException is thrown.
There is no limit to persistent subscriptions and shared non-persistent subscriptions with the same name and clientId. Such a subscription will be completely separate.
This method is the same as the corresponding createDurableSubscriber method, except that it returns a MessageConsumer instead of a TopicSubscriber to represent the consumer.
Parameter: Themes - Non-temporary topic subscriptions name - The name used to identify this subscription Throw: InvalidDestinationException - If an invalid topic is specified. IllegalStateException - If the guest identifier is not set JMSException - If the session fails to create a non-shared persistent subscription and MessageConsumer due to some internal error If a non-shared persistent subscription with the same name and client identifier already exists, and the consumer is already active If a shared persistent subscription with the same name and client identifier already exists Since: JMS 2.0 IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal);
where messageSelector is the message selector; The noLocal flag is false by default, and when set to true, it restricts consumers from only receiving messages published by the same connection as themselves, which is only applicable to topics, not queues. name is the unique identity of the subscription topic, and this parameter needs to be set when you subscribe to a persistent subscription.
Activemq .net needs to reference package download:The hyperlink login is visible.
Full source code download:
Tourists, if you want to see the hidden content of this post, please Reply
|