Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # .\util2.ps1 -hostname "activemq:tcp://w12dvipfmom01.ldstatdv.net:61617"
- # .\util2.ps1 -hostname "activemq:tcp://w12dvipfmom01.ldstatdv.net:61617"
- param(
- [Parameter(Mandatory=$true)]
- [string]$hostname
- )
- Add-Type -Path Apache.NMS.dll
- $global:queueName = ""
- $global:timer = New-Object System.Timers.Timer(5000)
- $global:runCount = 0
- $global:msmqHost = ""
- $global:daysOld = 0 # age of message in day
- $global:connected = $false
- $global:logOutputFolder = ""
- function global:GetActiveQueueMessage($activeMqHostUrl)
- {
- Write-Host "Connecting to the following activemq : $activeMqHostUrl" -ForegroundColor Cyan
- # Create connection
- $connection = CreateConnection $activeMqHostUrl
- try {
- $session = $connection.CreateSession()
- $target = [Apache.NMS.Util.SessionUtil]::GetDestination($session, "queue://$queueName")
- Write-Host "Establishing session to Queue : $target . $target.IsQueue " -ForegroundColor DarkCyan
- $connection.Start()
- Write-Host "Successfully started a connection to server." -ForegroundColor Green
- $topic = 'ActiveMQ.Advisory.Queue'
- $dest = $session.GetTopic($topic)
- $messageConsumer = $session.CreateConsumer($dest)
- Write-Host "Listing all the queue available:" -ForegroundColor Yellow
- while (($msg = $messageConsumer.Receive(2000)) -ne $null)
- {
- #Write-Host "*************************************"
- #Write-Host $msg
- Write-Host "--------------------"
- Write-Host $msg.DataStructure.Destination -ForegroundColor Green
- }
- Write-Host "Closing connection."
- $connection.Close()
- }
- catch {
- Write-Host "Core module error : $_.Exception.Message."
- }
- finally {
- CleanUp
- }
- }
- function global:CreateConnection($targetConnectionUrl)
- {
- Write-Host "Preparing connectivity info to $targetConnectionUrl at : $((Get-Date).ToString())"
- $uri = [System.Uri]$targetConnectionUrl
- Write-Host "Target activeMq location : $uri"
- $factory = New-Object Apache.NMS.NMSConnectionFactory($uri)
- $username = "admin"
- $password = "admin"
- try {
- $connection = $factory.CreateConnection($username, $password)
- Write-Host "Creating connection object : $connection" -ForegroundColor Green
- return $connection
- }
- catch {
- Write-Host "Connection to activeMq : $_.Exception.Message." -ForegroundColor Red
- }
- return $null
- }
- function Main($hostname)
- {
- # assignment to global variables
- $global:msmqHost = $hostname
- GetActiveQueueMessage $msmqHost
- }
- # Parameter
- # Execute main powershell module
- Main $hostname
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement