Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. # .\util2.ps1 -hostname "activemq:tcp://w12dvipfmom01.ldstatdv.net:61617"
  2. # .\util2.ps1 -hostname "activemq:tcp://w12dvipfmom01.ldstatdv.net:61617"
  3. param(
  4. [Parameter(Mandatory=$true)]
  5. [string]$hostname
  6. )
  7.  
  8. Add-Type -Path Apache.NMS.dll
  9.  
  10. $global:queueName = ""
  11. $global:timer = New-Object System.Timers.Timer(5000)
  12. $global:runCount = 0
  13. $global:msmqHost = ""
  14. $global:daysOld = 0 # age of message in day
  15. $global:connected = $false
  16. $global:logOutputFolder = ""
  17.  
  18. function global:GetActiveQueueMessage($activeMqHostUrl)
  19. {
  20. Write-Host "Connecting to the following activemq : $activeMqHostUrl" -ForegroundColor Cyan
  21. # Create connection
  22. $connection = CreateConnection $activeMqHostUrl
  23.  
  24. try {
  25. $session = $connection.CreateSession()
  26. $target = [Apache.NMS.Util.SessionUtil]::GetDestination($session, "queue://$queueName")
  27. Write-Host "Establishing session to Queue : $target . $target.IsQueue " -ForegroundColor DarkCyan
  28.  
  29.  
  30. $connection.Start()
  31. Write-Host "Successfully started a connection to server." -ForegroundColor Green
  32.  
  33. $topic = 'ActiveMQ.Advisory.Queue'
  34. $dest = $session.GetTopic($topic)
  35. $messageConsumer = $session.CreateConsumer($dest)
  36.  
  37.  
  38. Write-Host "Listing all the queue available:" -ForegroundColor Yellow
  39. while (($msg = $messageConsumer.Receive(2000)) -ne $null)
  40. {
  41. #Write-Host "*************************************"
  42. #Write-Host $msg
  43. Write-Host "--------------------"
  44. Write-Host $msg.DataStructure.Destination -ForegroundColor Green
  45. }
  46.  
  47. Write-Host "Closing connection."
  48. $connection.Close()
  49.  
  50. }
  51. catch {
  52. Write-Host "Core module error : $_.Exception.Message."
  53. }
  54. finally {
  55. CleanUp
  56. }
  57. }
  58.  
  59. function global:CreateConnection($targetConnectionUrl)
  60. {
  61. Write-Host "Preparing connectivity info to $targetConnectionUrl at : $((Get-Date).ToString())"
  62. $uri = [System.Uri]$targetConnectionUrl
  63. Write-Host "Target activeMq location : $uri"
  64. $factory = New-Object Apache.NMS.NMSConnectionFactory($uri)
  65.  
  66. $username = "admin"
  67. $password = "admin"
  68.  
  69. try {
  70. $connection = $factory.CreateConnection($username, $password)
  71. Write-Host "Creating connection object : $connection" -ForegroundColor Green
  72. return $connection
  73. }
  74. catch {
  75. Write-Host "Connection to activeMq : $_.Exception.Message." -ForegroundColor Red
  76. }
  77.  
  78. return $null
  79. }
  80.  
  81. function Main($hostname)
  82. {
  83. # assignment to global variables
  84. $global:msmqHost = $hostname
  85. GetActiveQueueMessage $msmqHost
  86.  
  87. }
  88.  
  89. # Parameter
  90. # Execute main powershell module
  91. Main $hostname
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement