Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Using with javascript SDK: Queue message result undefined #154

Closed
pirtthar opened this issue Feb 6, 2018 · 8 comments
Closed

Using with javascript SDK: Queue message result undefined #154

pirtthar opened this issue Feb 6, 2018 · 8 comments

Comments

@pirtthar
Copy link

pirtthar commented Feb 6, 2018

Hi,
I'm having trouble using the emulator through the javascript SDK. As I create a queue message, I can return it with the azure cli and with curl, but for some reason, the javascript result is undefined for peekMessage or getMessage. The plural versions return empty arrays. The funny thing is that I can see that the "response" part of the callback contains a message in the message-text.

I'm using the latest docker-version on azurite.

Have you stumbled upon this problem? All help is very much appreciated!

@jamesadarich
Copy link
Contributor

Are you using the azure-storage package from npm?

If so I have this working on a couple of my solutions with the functions mentioned.

Seems a bit strange, do you get any result items in your callback? Can you paste some code?

@pirtthar
Copy link
Author

pirtthar commented Feb 7, 2018

Hey, thanks for the response!

`import 'mocha'
import { expect } from 'chai'
import { QueueService, createQueueService, QueueMessageEncoder, ServiceResponse } from 'azure-storage'

describe('Test queue functions', () => {

let queueService: QueueService
const queueName = "test-queue"
const encoder = new QueueMessageEncoder.TextBase64QueueMessageEncoder()

before(() => {
    queueService = createQueueService()
})

beforeEach(() => {
    return new Promise((resolve, reject) => {
        queueService.createMessage(queueName, encoder.encode("test message"), (error: Error,result: QueueService.QueueMessageResult) => {
            if(error)
                reject(error)
            resolve(result)
        })
    })
})

it("peek message", () => {
    return new Promise((resolve, reject) => {
        queueService.peekMessage(queueName, (error: Error, result: QueueService.QueueMessageResult, response: ServiceResponse) => {
            if(error)
                reject(error)
            resolve(result)
        })  
    }).then((result: QueueService.QueueMessageResult) => {
        expect(result).not.eq(undefined)
        console.log(encoder.decode(result.messageText))
    })
    
})

})
`
I export the emulation parameter EMULATED=true

As a result, the test message seems to go into the queue. I can get a queue result using azure cli. After running the code, the result equals undefined. If I run the same code against an actual azure storage, the test passes. I know the test doesn't consume the messages, but I dropped the messages from the test queue manually. This code just tries to show the nature of my problem.

I'm missing something, I just don't know what...

@arafato
Copy link
Owner

arafato commented Feb 7, 2018

@pirtthar can you please run the following code on your environment:

const azure = require('azure-storage');
const queueSvc = azure.createQueueService('UseDevelopmentStorage=true');
queueSvc.createQueue('test-queue', (err, res) => {
    console.log('** CREATE QUEUE');
    console.log(JSON.stringify(err));
    console.log(JSON.stringify(res));
    queueSvc.createMessage('test-queue', 'testmessage', (err, res) => {
        console.log('** CREATE MESSAGE');
        console.log(JSON.stringify(err));
        console.log(JSON.stringify(res));
        queueSvc.peekMessage('test-queue', (err, res) => {
            console.log('** PEEK MESSAGE');
            console.log(JSON.stringify(err));
            console.log(JSON.stringify(res));
        });
    });
});

What is the output of this script?

In the console it should be similar to this:

** CREATE QUEUE
null
{"name":"test-queue"}
** CREATE MESSAGE
null
{"messageId":"5f23253c-5641-434d-8f5f-22c5d19c7e83","insertionTime":"Wed, 07 Feb 2018 13:02:50 GMT","expirationTime":"Wed, 14 Feb 2018 13:02:50 GMT","popReceipt":"e11242da-265b-4a7d-b6c9-fa368705363b","timeNextVisible":"Wed, 07 Feb 2018 13:02:50 GMT"}
** PEEK MESSAGE
null
{"messageId":"5f23253c-5641-434d-8f5f-22c5d19c7e83","insertionTime":"Wed, 07 Feb 2018 13:02:50 GMT","expirationTime":"Wed, 14 Feb 2018 13:02:50 GMT","dequeueCount":0,"messageText":"testmessage"}

The Azurite log output should be similar to this:

PUT /devstoreaccount1/test-queue 201 9.794 ms - -
POST /devstoreaccount1/test-queue/messages 201 24.356 ms - 452
GET /devstoreaccount1/test-queue/messages?numofmessages=1&peekonly=true 200 3.960 ms - 395

Can you confirm? Thanks!

@pirtthar
Copy link
Author

pirtthar commented Feb 7, 2018

I ran the given code and the result was:

** CREATE QUEUE
null
{"name":"test-queue"}
** CREATE MESSAGE
null
undefined
** PEEK MESSAGE
null
undefined

So I decided to remove my azurite docker image and start from the beginning. It turns out I didn't have the latest docker image. I updated and your example and my test both worked out of the box!

It is a bit unclear what had happened in my environment, but in any case azurite works as it should.

Thank you @jamesrichford and @arafato for your assistance and support! I truly appreciate what you guys are doing with Azurite. It gives us non-windows coders a great way to test storage-related code.

@pirtthar pirtthar closed this as completed Feb 7, 2018
@thisisthekap
Copy link
Contributor

@pirtthar How do you reference the docker-image? (which tag are you using)

@arafato
Copy link
Owner

arafato commented Feb 7, 2018

@thisisthekap IMHO the easiest way would be as described here https://github.com/arafato/azurite#pulling-from-docker-hub

If you want the latest version use the latest tag like so

$ docker pull arafato/azurite:latest

If you want a specific version, e.g. 1.8.5 pull the image like so:

$ docker pull arafato/azurite:1.8.5

@pirtthar
Copy link
Author

pirtthar commented Feb 7, 2018

@thisisthekap

REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
arafato/azurite                latest              94688648cb1c        2 days ago          103 MB
arafato/azurite                <none>              6f955b822ccb        8 days ago          102 MB
arafato/azurite                <none>              cd37d3e02c54        3 weeks ago         103 MB

I use the default setting, which is latest. I pasted the list of images that have been used in my environment. According to docker hub, 1.8.6 - 1.8.4.

@thisisthekap
Copy link
Contributor

@pirtthar

I would strongly recommend you to use specific version tags. if you use latest, the image won't be updated when a new version is available, because the tag latest is already present locally.

Additionally, specific version tags have the advantage, that everybody of your dev team uses exactly the same environment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants