In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what the VB.NET message queue is, the article is very detailed, has a certain reference value, interested friends must read it!
Message queuing is the basis of communication in the Windows 2000 operating system (NT also has MSMQ,WIN95/98/ME/XP without message queuing service but supports client operation). It is also a tool for creating distributed, loosely connected communication applications. These applications can communicate over different kinds of networks or with offline computers. VB.NET message queue is divided into user-created queue and system queue, and user queue is divided into:
Common queues are replicated and transmitted across the entire VB.NET message queuing network that can deliver messages, and may be accessed by all sites connected to the network.
Private queues are not published throughout the network. Instead, they are available only on the local computer where they reside. Private queues can only be accessed by applications that know the full pathname or label of the queue.
The Administrative queue contains messages that confirm the receipt of messages sent in a given message queuing network. Specify the administrative queue that you want the MessageQueue component to use
The response queue contains a response message returned to the sending application when the target application receives the message. Specify the response queue that you want the MessageQueue component to use.
The system queue is divided into:
Journal queue optionally stores copies of messages sent and copies of messages removed from the queue.
The Dead letter queue stores copies of messages that cannot be delivered or have expired.
A dedicated system queue is a dedicated queue for managing and notifying messages required by a storage system to perform message processing operations.
Now that you have a simple understanding of VB.NET message queuing, it's time to get to the topic. To use MSMQ for software development, MSMQ is required. After installation, you should enter the actual development phase. First open "Server Explorer" in IDE to expand the name of the computer where you want to create a message queue, and then expand "message queue". Right-click it and select "New" from the pop-up menu to create a new message queue, and give it a name, which is optional. It can also be done programmatically, as follows:
System.Messaging.MessageQueue
.Create (".\ Private$\ MyPrivateQueue")
'set up a dedicated queue
System.Messaging.MessageQueue.
Create ("myMachine\ MyQueue")
'set up a public queue
In fact, I don't think it's important to use which method, it's important to figure out the difference between private queues and public queues (other queues are not necessary). In this example, private queues and public queues are established on the server through Server Explorer.
Program function: this procedure is divided into two parts, including the server program (installed on the SQL Server server) and the client program, the role of the client is to write t-sql statements and put t-sql statements in the message, and send the message to the message queue on the SQL Server server. The server program checks the specified VB.NET message queue and starts to execute the contents of the message when it finds that a new message arrives. Because the contents of the message are t-sql statements, the server actually performs the operation on the database.
Client program:
Public Sub client ()
Dim tM As New System.Messaging.
MessageQueue ()
TM.Path = ".\ Private$\ jk"'
"FORMATNAME:PUBLIC=3d3dc813-
C555-4fd3-8ce0-79d5b45e0d75 "
'establish a connection to the message queue on the specified computer
Dim newMessage As New System.
Messaging.Message (TextBox1.Text)
'accept the t-sql statement of the text basket
NewMessage.Label = "This is
The label "'message name
TM.Send (newMessage) 'send message
End Sub
Server programs:
Public Sub server ()
Dim NewQueue As New System.Messaging
.MessageQueue (".\ Private$\ jk")'
"FORMATNAME:PUBLIC=3d3dc813-c555-
4fd3-8ce0-79d5b45e0d75 "'and designated computer
Establish a connection by message queuing in
Dim m As System.Messaging.Message
'View messages in the VB.NET message queue
M = NewQueue.Receive
M.Formatter = New System.Messaging.
XmlMessageFormatter (New String ()
{"System.String,mscorlib"})
Dim st As String
St = m. Body` message content of the message in the message queue.
Already sql statement
Dim con As New OleDb.OleDbConnection
(enter your own database connection string)
Con.Open ()
Dim com As New OleDb.OleDbCommand
(st, con) 'execute the sql statement in the message
Com.ExecuteNonQuery ()
Con.Close ()
End Sub
In this program, you will find that I do not connect to the database and request data in sub client (). Instead, I operate the database by sending messages, which saves two parts of time:
1. The time to unlock the requested data from the database.
2. Time to return data from the database.
In many cases, we don't need to see the specific data to know how to modify the data in the database. For example, to delete Zhang San's record, you can put a simple delete statement into the message and send it to the server to let the server program deal with the changes to the data.
In addition, another main use of VB.NET message queues, which is indispensable in the current ERP software, is to save information when disconnected and send messages when the connection is restored. Messages cannot be delivered to their queues quickly in two situations: when the computer on which the queue resides does not work, or when the domain controller required to route messages does not work. Message queuing allows you to deal with these situations so that you can continue to send messages when you are disconnected from the network or when the necessary computers or controllers fail to work. In these cases, the message is temporarily stored in the queue of a computer on the local computer or on the delivery route until the resources required to complete the delivery come back online.
For example, suppose you have a central queue that records orders sent by all traveling salespeople. These salespeople work disconnected for most of the day, record order information from customer sites, and dial up once a day to transmit all this information to a central queue. Because messages can still be sent to the queue when the sender is disconnected, the salesperson can send their messages immediately when the customer information is recorded, but the system caches the messages until a dial-up connection is made at night.
How do I save the message when I disconnect? Sending a message to a disconnected queue is almost exactly the same as sending a message to an available queue. When the queue to be sent to is not available, no special configuration is required for the component to store messages in a temporary queue. There is a comment statement after tM.Path = ".\ Private$\ jk" in the client code, which actually implements the function of sending messages to disconnected queues. Just replace the statement tM.Path = ".\ Private$\ jk" with tM.Path = "FORMATNAME:PUBLIC=3d3dc813-c555-4fd3-8ce0-79d5b45e0d75" where the number after PUBLIC is the guid number to be sent to the computer.
This number can be seen by opening the properties of the message queue on that computer. Using this method, you can ensure that the operation to the server is effective in the case of disconnection. Now after running this program, open computer Management, expand "Services and applications"-"message queuing"-"outgoing queue" in the "computer Management" window, and you will see the message you created in the window on the right. If you use the tM.Path = ".\ Private$\ jk" statement, expand "Services and applications"-"message queues"-"Private queues" in the computer Management window to see the queues you have created. )
In fact, the programming of message queue is not complex, but it is very useful in the program development of network environment, which can simplify a lot of development process and save development time. Moreover, message queuing programming has great flexibility and can almost solve most of the problems of network programming. Such as chat programs, remote control programs.
This paper gives a brief introduction to VB.NET message queue and gives an example to illustrate how to use message programming in .NET to operate the database quickly, efficiently and stably. * add that message queuing can also be used in Internet, as long as you change the number after the tM.Path = "FORMATNAME:PUBLIC=3d3dc813-c555-4fd3-8ce0-79d5b45e0d75 statement into the number of the server where the message queue resides. But to remind you that using messages will take up a lot of bandwidth during transmission, so programming under Internet should not use messages when it is not necessary.
These are all the contents of the article "what is the VB.NET message queue?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.